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

一个人想着一个人 提交于 2020-01-05 07:10:36

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!