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

Posted by Newbie on Stack Overflow See other posts from Stack Overflow or by Newbie
Published on 2010-04-28T09:09:11Z Indexed on 2010/04/28 9:13 UTC
Read the original article Hit count: 217

Filed under:

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)

© Stack Overflow or respective owner

Related posts about c#3.0