I would like to know if anyone knows the difference between these two ways of declaring multidimensional arrays in c#
.
string[][] m = new string[2][]; // primera forma
string[,] m2 = new string[2, 2]; // segunda forma
And because when I declare it as follows:
string[][] m = new string[2][2]; // <- me marca un error
It gives me an error when assigning the second length between the second pair of square brackets.
As a note I want to mention that I always declare them in the second way mentioned in the first code block.
One is an array of arrays, and the other is a 2d array.
That is, a double [] [] can be valid like this:
Because each entry in the array is a reference to another array of string. Stepwise, you can do an assignment to an array like you do with the second way.
Another important difference is that the 2d matrix is uniform, and therefore a 1d matrix cannot be assigned to a row or column. That is, by obligation you have to give the index of the row and column.
I hope I solve your doubt.