gpt4 book ai didi

c# - 无法将类型 'System.Numerics.BigInteger' 隐式转换为 'int' 。存在显式转换(您是否缺少转换?)

转载 作者:行者123 更新时间:2023-11-30 13:53:57 25 4
gpt4 key购买 nike

我有一个数组和简单的循环:

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;
}
}

谁能解释为什么这段代码返回

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

错误出现在这一行:

BigInteger[] Vector = new BigInteger[num]; 

一切都转换为 BigInteger,我看不出可能的原因。

将感谢您的帮助,

提前致谢

最佳答案

num 是一个 BigInteger 但您正在使用它来初始化数组的大小:

BigInteger[] Vector = new BigInteger[num];

数组的索引器是 int,这意味着您可以创建的最大大小是 int.MaxValue (2,147,483,647)。

关于c# - 无法将类型 'System.Numerics.BigInteger' 隐式转换为 'int' 。存在显式转换(您是否缺少转换?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50290824/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com