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
}
}
Stuck on this for a while now. The exact error is “Index was outside the bounds of the array”. I do not know to which index this refers however.
Looks like you accidentally wrote <= instead of <. Remember that array indices go up to the length – 1.
I might recommend cleaning up the code a bit. That’s a lot of extra brackets and variables…