public void button2_Click(object sender, EventArgs e)
{
char[] delimiters = { ',', '\r', '\n', ' ' };
string[] content = File.ReadAllText(CSV_File).Split(delimiters);
int bounds = (content.GetUpperBound(0)); //bounds of this content string is 96
int i = 1;
id = new string[(bounds / 4)]; //for example index size = 96 / 4 = 24
for (i = 0; i <= (bounds / 4); i++)
{
int rows = (i * 4); // gets every 4th value
id[i] = content[rows]; //inserts row 96 into id 24 - fails here
}
}
现在坚持了一段时间。确切的错误是“索引超出了数组的范围”。但是我不知道这是指哪个索引。
最佳答案
更改 <=
至 <
在 for 循环中。
关于c# - 为什么这会导致 'Index out of range' 异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8958521/