7

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?

3

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

@MAfifi No, rectangular. It's possible to have 16 x 9 for example using object[,]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.