Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert single dimensional arrays to multi dimensional ones? (C#)

I have to use a method which accepts double[,], but I only have a double[]. How can I convert it?

Solution so far:

var array = new double[1, x.Length];
foreach (var i in Enumerable.Range(0, x.Length))
{
    array[0, i] = x;
}
like image 713
Jader Dias Avatar asked Dec 01 '22 12:12

Jader Dias


1 Answers

There's no direct way. You should copy stuff into a double[,]. Assuming you want it in a single row:

double[,] arr = new double[1, original.Length];
for (int i = 0; i < original.Length; ++i) 
    arr[0, i] = original[i];
like image 50
mmx Avatar answered Dec 05 '22 16:12

mmx