C# How do I parse a text file of data of unknown row size to a 2D array?
I can easily pass a data file to a 2D array if I know the size of the data
file, but thats pretty pointless when you want to add and remove data.
How can I instantiate a 2D array of that Data rows length that is global
and not out of scope to the rest of the program?
Here is the usual code, for an array of 4 rows and 6 columns, but I want
to add/remove data to the data file making it of unknown length in rows.
string[,] allStudentData = new string[4, 6];
string[] allStudents = File.ReadAllLines("data.txt");
for (int i = 0; i < allStudents.Count(); i++)
{
for (int j = 0; j < 6; j++)
{
string[] DataIn = allStudents[i].Split(',');
allStudentData[i, j] = DataIn[j];
}
}
Thanks for your ideas :-)
No comments:
Post a Comment