I confuse between double[][] and double[,] in C#.
My teammate give me a function like this:
public double[][] Do_Something(double[][] A)
{
.......
}
I want to use this function:
double[,] data = survey.GetSurveyData(); //Get data
double[,] inrma = Do_Something(data);
It lead an error: invalid argument.
I don't want to edit my teammate's code.
Does it have any way to convert double[][]
to double [,]
?
Thanks!
A double[][]
is an array of double[] (An array of arrays)
but double[,]
is a single 2 dimensional double array
Example :
double[] Array1 = new double[] {1,2,3};
double[] Array2 = new double[] {4,5,6};
double[][] ArrayOfArrays = new double[][] {Array1,Array2};
double[,] MultidimensionalArray = new double[,] {{1,2}, {3,4}, {5,6}, {7,8}};
double[][]
and double[,]
have different meanings.
double[][]
is jagged, so some elements can be of different lengths than others.
double[,]
is "rectangular", so all elements are of the same length.
You could write a method to "convert" between the two, but how will you rectify the differences? I.e. how will you decide to "trim" from the long elements or expand the short elements in order to make it rectangular?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With