Problem : You have the Extra EmptyLines after every Line in your text file.
when Split() function encounters a new Line it returns as it is becaue there is nothing to split and Add()
function throws exception as empty line is not a valid Double
.
Solution1 : You can Use StringSplitOptions.RemoveEmptyEntries
as second argument to Split()
function to ignore the EmptyLines.
foreach (var line in File.ReadAllLines(path))
{
// HERE IS THE ERROR
rows.Add(line.Split(new[] { ' ' },StringSplitOptions.RemoveEmptyEntries).Select(double.Parse).ToArray());
}
Solution 2: you can check wether line is Empty or not by using String.IsNullOrWhiteSpace()
foreach (var line in File.ReadAllLines(path))
{
if(!String.IsNullOrWhiteSpace(line))
{
// HERE IS THE ERROR
rows.Add(line.Split(new[] { ' ' },StringSplitOptions.RemoveEmptyEntries).Select(double.Parse).ToArray());
}
}