This is driving me literally insane for some reason my code to read a simple text file of ints into an int array wont work.
private void HardButton_Click(object sender, EventArgs e)
{
int[] hard1 = { };
int counter = 0;
using (StreamReader inFile = new StreamReader("h1.txt"))
{
string str = null;
while ((str = inFile.ReadLine()) != null)
{
hard1[counter] = Convert.ToInt32(str);
counter++;
}
}
hard1 is an array of ints that i need to hold each integer placed into it by reading the text file. My error is that my array is out of bounds even though I'm iterating each time through the loop. I am at a loss.
EDIT: Here is the txt file input
0502090
6070203
0502010
5020101
0503010
4020905
0608070
7582391
6478283
8592914
5628191
6573812
4728915
3648271
int[] hard1 = { };does? i.e. what is the length ofhard1?