I have a question concerning LINQ queries and return types. I just want to read values from a .csv file, where there are double values separated by semicolon like this:
0,016;0,010;-0,020;-0,014;0,020;0,016;-0,019;-0,014;0,023;
The reading from the file works fine with the following statement:
double pdValue;
double[] pdValues;
var values = File.ReadAllLines(path)
.Select(a => a.Split(';')
.Select(str => double.TryParse(str, out pdValue) ? pdValue : 0));
pdValues = values.ToArray();
But the last line returns the 'Cannot implicitly convert System.Collections.Generic.IENumerable< double> to double[]' error. Trying to get it to work with array changes the error to 'Cannot implicitly convert System.Collections.Generic.IENumerable< double>[] to double[]'.
When debugging, I can already see that the values variable holds all values from the file (somehow) as array...
I could not find anything yet, what could give me a hint on what exactly I am doing wrong here. Can anybody help me?
Thanks in advance!
File.ReadLinesinstead of theFile.ReadAllLines, because theFile.ReadLinesstreams the data instead of loading it full into the memory.double[][]What do you need as result?double[][]ordouble[](all lines merged)