I am wondering what is the difference between the two ways to define a Multidimensional Array in C#.
You can use object[][]
and object[,]
to work with multidimensional array.
Are there functional differences?
I am wondering what is the difference between the two ways to define a Multidimensional Array in C#.
You can use object[][]
and object[,]
to work with multidimensional array.
Are there functional differences?
The object[][]
is a notation for array of arrays. The second one object[,]
is a two dimensional array.
The main difference is while the first one can contain different length "inner" arrays, the second one must be rectangular (e.g. 4x7).
Example:
int[][] a = new int[] { new int[]{ 1, 2 }, new int[]{ 3, 4, 5, 6, 7 }};
int[,] b = new int[,] { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 } };