6

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?

hwcverwe
  • 5,287
  • 7
  • 35
  • 63

1 Answers1

8

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 } };

This is an official tutorial.

Matzi
  • 13,770
  • 4
  • 33
  • 50