IEnumerable<string[]> allLines = File.ReadAllLines(@"C:\ArsScale\Tars.csv").Select(x => x.Split(','));
This will read all the lines from the text file, then split each line. The datatype will be IEnumerable
of string[]
. To change this to string[][]
, simply call .ToArray()
after the Select
statement.
This method is quick and simple, however it does absolutely no validation on the input. For example, the CSV spec allows for commas to be present inside of values as long as they are escaped. If you need to have validation of any kind, you need to look into a CSV parser, of which there are many.
If you need no validation, you're positive about the input, and don't care about good error handling, you can use the following:
var allLines = File.ReadAllLines(@"C:\ArsScale\Tars.csv").Select(x => x.Split(',').Select(y => double.Parse(y).ToArray())).ToArray();
This will give you double[][]
as your output.