c#索引在数组的边界之外,永远不会脱离for循环

Joe*_*oel 0 c# arrays for-loop

我的程序编译但是当它运行时,它永远不会脱离循环并且表示数组太大了.这是我的代码:

public class ComparableArray
{   
    public static void Main()
    {
    taxpayer[] taxArray = new taxpayer[5];
    int x;
    for(x= 0; x < taxArray.Length; ++x)
        taxArray[x] = new taxpayer();

        Console.Write("Enter Social Security Number for taxpayer {0}: ", x+1);
        taxArray[x].SSN = Console.ReadLine();
                    Console.Write("Enter gross income for taxpayer {0}: ", x+1);
                    taxArray[x].Income = Convert.ToDouble(Console.ReadLine());
        taxpayer.getRates();
        x++;

    }
}
Run Code Online (Sandbox Code Playgroud)

我不确定我做错了什么,我很感激任何帮助.

ant*_*awn 5

你在循环中递增x两次:

来到这里:

for(x= 0; x < taxArray.Length; ++x)
Run Code Online (Sandbox Code Playgroud)

在这里:

x++;
Run Code Online (Sandbox Code Playgroud)