I\'m trying to parse a CSV file into a 2D array in C#. I\'m having a very strange issue, here is my code:
string filePath = @\"C:\\Users\\Matt\\Desktop\\Eve Spre
Nothing in your code gets the number of lines out of your file in time to use it.
Line.Length
represents the number of columns in your csv, but it looks like you're also trying to use it to specify the number of lines in your file.
This should get you your expected result:
string filePath = @"C:\Users\Matt\Desktop\Eve Spread Sheet\Auto-Manufacture.csv";
StreamReader sr = new StreamReader(filePath);
var lines = new List();
int Row = 0;
while (!sr.EndOfStream)
{
string[] Line = sr.ReadLine().Split(',');
lines.Add(Line);
Row++;
Console.WriteLine(Row);
}
var data = lines.ToArray();