Possible Duplicate:
How can I convert a list<> to a multi-dimensional array?
I want to have an array in form of double[,] for this purpose since I do not know what will be the length of this array, I want to make a List first then later using List<T>.ToArray() convert it to double[,]:
public double[,] FilterClampedData(double[,] data)
{
var finalData = new List<double[]>();
//Do some stuff on parameter
return finalData.ToArray(); ///Does not compile :(
}
Since
ToArrayreturns a one-dimensional array, there is no wonder why this does not compile. If you were returningdouble[][], it would compile, however. You could also build your 2-D array manually with two nested loops:The code above assumes that you have at least one item in the
finalData, and that the length of all lists insidefinalDatais the same.