C#-for循环的问题。索引超出数组边界-为什么程序不';不要跳出for循环并继续
所以我的问题是,我想在for循环之后打印出信息,但它从未真正到达代码。有没有具体的原因,或者我应该将所有内容都放在for循环的范围内? 数组束外的索引C#-for循环的问题。索引超出数组边界-为什么程序不';不要跳出for循环并继续,c#,for-loop,indexoutofboundsexception,C#,For Loop,Indexoutofboundsexception,所以我的问题是,我想在for循环之后打印出信息,但它从未真正到达代码。有没有具体的原因,或者我应该将所有内容都放在for循环的范围内? 数组束外的索引 `int sumEven=1, sumOdd=1; Console.WriteLine("Give the amount of numbers: "); int amount = int.Parse(Console.ReadLine()); Console.WriteLin
`int sumEven=1, sumOdd=1;
Console.WriteLine("Give the amount of numbers: ");
int amount = int.Parse(Console.ReadLine());
Console.WriteLine("Numbers: ");
int[] numberInputs = new int [amount];
for (int inc = 1; inc <= amount; inc++)
{
numberInputs[inc] = int.Parse(Console.ReadLine());
if (inc % 2 == 0)
{
sumEven *= numberInputs[inc];
}
else
{
sumOdd *= numberInputs[inc];
}
}
if (sumEven == sumOdd)
{
Console.WriteLine("Yes\n");
Console.Write($"Product = {sumEven}");
}
else if (sumEven != sumOdd)
{
Console.Write("No\n");
Console.WriteLine($"Even product = {sumEven}");
Console.WriteLine($"Odd product = {sumOdd}");
}
`int-sum偶数=1,sum奇数=1;
Console.WriteLine(“给出数字的数量:”);
int amount=int.Parse(Console.ReadLine());
控制台。WriteLine(“数字:”);
int[]numberInputs=新的int[金额];
对于(int inc=1;inc尝试使用incfor (int inc = 0; inc < amount; inc++)
{
numberInputs[inc] = int.Parse(Console.ReadLine());
if (inc % 2 == 0)
{
sumEven *= numberInputs[inc];
}
else
{
sumOdd *= numberInputs[inc];
}
}
for (int inc = 1; inc < amount; inc++)
{
numberInputs[inc] = int.Parse(Console.ReadLine());
if (inc % 2 == 0)
{
sumEven *= numberInputs[inc];
}
else
{
sumOdd *= numberInputs[inc];
}
}