Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot implicitly convert type 'System.Numerics.BigInteger' to 'int'. An explicit conversion exists (are you missing a cast?)

Tags:

c#

.net

I have an array and simple loop:

static BigInteger[] dataSet = new BigInteger[] { 100913, 1009139, 10091401, 100914061, 1009140611, 10091406133, 100914061337, 1009140613399 };


 foreach (BigInteger num in dataSet ) {

                BigInteger[] Vector = new BigInteger[num];

                for (BigInteger i = 1; i <= num; i++)  {
                    Vector[i - 1] = i;
                }
            }

Can anyone explain why this code returns

Cannot implicitly convert type 'System.Numerics.BigInteger' to 'int'. An explicit conversion exists (are you missing a cast?)

Error appears in this line:

BigInteger[] Vector = new BigInteger[num]; 

Everything is converted to BigInteger, I do not see the possible reasons.

Will be thankful for help,

Thanks in advance,

like image 254
vba_user Avatar asked May 28 '26 18:05

vba_user


1 Answers

num is a BigInteger but you are using it to initialise the size of your array:

BigInteger[] Vector = new BigInteger[num];

The indexer of an array is int, meaning that largest size you can create is int.MaxValue (2,147,483,647).

like image 190
DavidG Avatar answered May 31 '26 08:05

DavidG



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!