I am learning how to do multidimensional arrays and I am getting this reference error while trying to populate the array. Anyone have any ideas?
public static string[][] itemLines;
public static void readTxtFile()
{
try
{
string[] lines = new string[420];
using (StreamReader sr = new StreamReader(TextFileDirectory.fileDirectoryThree))
{
int counter = 0;
while (!sr.EndOfStream)
{
lines[counter] = sr.ReadLine(); //All lines are in an array index
counter++;
}
}
for (var i = 0; i < lines.Length; i++)
{
itemLines[i] = lines[i].Split('Ü'); //All lines are in multiplexed array
Console.WriteLine("Line " + i + "'s first value is: " + itemLines[i][0]);
}
}
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
This is kicking my butt. I can't seem to figure this out.
Edit: I found the answer out. I had to have a counter variable and declare the arrays correctly with it.