问题
I have two lists x1 and x2 of type double
List<double> x1 = new List<double> { 0.0330, -0.6463};
List<double> x2 = new List<double> { -0.2718, -0.2240};
I am using the below function to convert it to double array
List<List<double>> xData = new List<List<double>> { x1, x2 };
double[,] xArray = new double[xData.Count, xData[0].Count];
for (int i = 0; i < xData.Count; i++)
{
for (int j = 0; j < xData[0].Count; j++)
{
xArray[i, j] = xData[i][j];
}
}
Is it possible to do the same stuff (i.e. the function that is converting List to array) by using Linq.
Using : (C#3.0) & Framework - 3.5
I want to do this by using Linq because I am learning it but not have sufficient knowledge to write that.
Thanks
Convert List to Double Array by LINQ (C#3.0)
回答1:
There may be some way of doing it, but I don't believe LINQ has any built-in support for rectangular arrays.
来源:https://stackoverflow.com/questions/2728076/convert-list-to-double-array-by-linq-c3-0