bjeverett
asked on
Is This A C# Multidimensional Array?
What does "Object[ ] [ ]" represent in C#? I thought it's a multidimensional array, but isn't that represented by "Object[ , ]"? How can I initialize an object of type "Object[ ][ ]"? Thanks.
Yes, that is a two dimensional array.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
With [,] notation, the arrays within the top level array have the same capacity which makes it truly a multidimensional array. As you can see by my example, you can make all the arrays have the same size by initializing in loop. However, the difference in the jagged version (array of arrays) is technically you can have arrays of different dimensions at the 2nd and subsequent levels.
ASKER
Thanks for the quick response, mwvisa. I was having a little trouble with the initialization, but you're example cleared things up.
they are both 2 dimensional arrays. the only difference between them is that Object[,] is always a rectangular one and the Object[][] can be a jagged array - it doesn't need to be rectangular.
Initialization can be done like this:
int[][] jaggedArray = new int[6][];
jaggedArray[0] = new int[4] { 1, 2, 3, 4 };
Initialization can be done like this:
int[][] jaggedArray = new int[6][];
jaggedArray[0] = new int[4] { 1, 2, 3, 4 };
Thanks, emce. Rectangular Array is what I meant as they are both definitely multidimensional. :)