通过LINQ(C#3.0)将列表转换为双精度数组

问题描述:

我有两个类型为double的列表x1和x2

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];
                }
            }

是否可以做同样的事情(即将List转换为数组的函数)。

使用:(C#3.0)&框架-3.5

我想使用Linq来做到这一点,因为我正在学习它,但没有足够的知识来编写它。

I want to do this by using Linq because I am learning it but not have sufficient knowledge to write that.

谢谢

通过LINQ(C#3.0)将列表转换为双精度数组

Convert List to Double Array by LINQ (C#3.0)

可能有一些方法,但是我不认为LINQ内置了对矩形数组的支持。

There may be some way of doing it, but I don't believe LINQ has any built-in support for rectangular arrays.