How to convert List<int[]>
to int[,]
where all arrays in the list are int[2]
?
I'm trying:
List<int[]> list = new List<int[]>();
list.Add(new int[2] { 3, 4 });
int[,] arr = list.ToArray();
How to convert List<int[]>
to int[,]
where all arrays in the list are int[2]
?
I'm trying:
List<int[]> list = new List<int[]>();
list.Add(new int[2] { 3, 4 });
int[,] arr = list.ToArray();
You can't convert List to int[,] via LINQ
.
You need to create new array [N, 2]
and fill in a loop:
var arr = new int[list.Count, 2];
for (var i = 0; i < list.Count; i++)
{
arr[i, 0] = list[i][0];
arr[i, 1] = list[i][1];
}