Difference between multidimensional notes of an array (object [] [] and object [,])

I am wondering what is the difference between the two ways to define a multidimensional array in C #.

You can use object[][]it object[,]to work with a multidimensional array.

Are there functional differences?

+5
source share
1 answer

object[][]is the designation for an array of arrays. The second object[,]is a two-dimensional array.

The main difference is that the first can contain different internal "arrays", the second must be rectangular (for example, 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 the official guide.

+6
source

All Articles