Converting List<T> to Array (multidimensional)
Since ToArray
returns a one-dimensional array, there is no wonder why this does not compile. If you were returning double[][]
, it would compile, however. You could also build your 2-D array manually with two nested loops:
var R = finalData.Count;
var C = finalData[0].Length;
var res = new double[R, C];
for (int r = 0 ; r != R ; r++)
for (int c = 0 ; c != C ; c++)
res[r, c] = finalData[r][c];
return res;
The code above assumes that you have at least one item in the finalData
, and that the length of all lists inside finalData
is the same.