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
A shorter version of the code above:
var filePath = @"C:\Users\Matt\Desktop\Eve Spread Sheet\Auto-Manufacture.csv";
var data = File.ReadLines(filePath).Select(x => x.Split(',')).ToArray();
Note the user of ReadLines
instead of ReadAllLines
, which is more efficient on larger files as per MSDN documentation:
When you use ReadLines, you can start enumerating the collection of strings before the whole collection is returned; when you use ReadAllLines, you must wait for the whole array of strings be returned before you can access the array. Therefore, when you are working with very large files, ReadLines can be more efficient.