CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2014
    Posts
    10

    Question Integral constant is too large: How to put a thousand 50-digits integers in an array?

    Hello.

    I'm using the software SharpDevelop (C#).

    I've created a list of integers (array) like this:

    int[] name = new int[number-of-elements]{elements-separated-by-commas}

    In the {} I would like to put 1000 integers, half of those having more than 50 digits.

    But when I do that I get the following error:

    "Integral constant is too large (CS1021)"

    So how to solve this problem?

    Note that I am a complete novice in programming, so please try to explain everything clearly.

    Thanks in advance for your answers.
    Last edited by Core Crash; October 11th, 2014 at 11:47 AM.

  2. #2
    Join Date
    Apr 2014
    Location
    in northeast ohio
    Posts
    94

    Re: Integral constant is too large (CS1021) - How to put 1000 integers in an array?

    your error
    http://msdn.microsoft.com/en-us/libr...=vs.90%29.aspx
    occuring because a int's max value is 10 digits
    http://www.dotnetperls.com/int-maxvalue
    a ulong can take about 20 digits
    for a 50 digit number you will probably need something more advanced
    that takes a string representation most likely as a form of input and output
    you will simply have to look into that yourself google
    "c# big numbers or big number class or library"
    http://www.codeproject.com/Articles/...lass-Done-in-C
    Last edited by willmotil; October 12th, 2014 at 09:58 AM.

  3. #3
    Join Date
    Oct 2014
    Posts
    10

    Re: Integral constant is too large (CS1021) - How to put 1000 integers in an array?

    Thanks for your answer, but I already found the answer to my question: the BigInteger Structure.

    BigInteger[] name = new[]
    {
    BigInteger.Parse("first-integer"),
    BigInteger.Parse("second-integer"),
    BigInteger.Parse("third-integer"),
    ...
    ...
    };

    And my program works now.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured