C# 在数组c的边界之外#

C# 在数组c的边界之外#,c#,C#,我不断地出错,我不知道为什么,有人告诉我为什么这不起作用。它不仅给我一个错误,而且无法将第二个输入存储到userInput[1] string[] name = new string[4]; double[] bankAccount = new double[4];; int x; for (x = 0; x <= name.Length; x++) { Console.Write("Please enter first Name and their bank status:

我不断地出错,我不知道为什么,有人告诉我为什么这不起作用。它不仅给我一个错误,而且无法将第二个输入存储到userInput[1]

string[] name = new string[4];
double[] bankAccount = new double[4];;

int x;
for (x = 0; x <= name.Length; x++)
  {
    Console.Write("Please enter first Name and their bank status: ");
    string[] userInput = Console.ReadLine().Split();
    name[x] = userInput[0];
    bankAccount[x] = double.Parse(userInput[1]);
    Console.WriteLine(userInput[0], userInput[1]);
  }
string[]name=新字符串[4];
double[]银行账户=新的double[4];;
int x;

对于(x=0;x,您可能知道,数组总是从索引0开始计算元素

string[] stringArray = { "Hello", "There" };
Console.WriteLine(stringArray.length); // this will output 2, because there are two elements
Console.WriteLine(stringArray[0]); // this will output hello, and [1] would output there
发生了什么事?
对于(x=0;x,您可能知道,数组总是从索引0开始计算元素

string[] stringArray = { "Hello", "There" };
Console.WriteLine(stringArray.length); // this will output 2, because there are two elements
Console.WriteLine(stringArray[0]); // this will output hello, and [1] would output there
发生了什么事?
用于(x=0;x
x
not
谢谢,它成功了。我很好奇为什么?如果我想运行5次,我假设它从0到4,我没有得到什么?@BrianNaranjo如果将数组的长度设置为4,你就不能转到
x
not
的第5个不可扩展副本,谢谢,它成功了。我是c为什么?如果我想运行5次,我假设它会从0到4,我没有得到什么?@BrianNaranjo你将数组的长度设置为4,你不能到第5个不可能重复的数组总是以1开始计数元素?哦,谢谢,很好的解释。我很困惑,因为我认为将数组设置为长度4会起作用lly给我5个元素,而不是4个。你应该编辑它,使它至少是一致的。数组总是从1开始计数元素是完全错误的,以后你写访问元素时会从0开始计数。这让人困惑,特别是对于新的程序员来说,他们不知道哪一个是正确的。我的错,我似乎混淆了数组总是以1开始计数元素?哦,谢谢,很好的解释。我很困惑,因为我认为将数组的长度设置为4实际上会给我5个元素,而不是4个。你应该编辑它,使其至少保持一致。数组总是以1开始计数元素是完全错误的,以后你写访问元素时会出错从0开始计数。这会让人困惑,尤其是对于那些不知道哪一个是正确的新程序员。我的错,我似乎把事情搞混了