Link to home
Start Free TrialLog in
Avatar of bjeverett
bjeverettFlag for United States of America

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.
Avatar of Kevin Cross
Kevin Cross
Flag of United States of America image

Yes, that is a two dimensional array.
ASKER CERTIFIED SOLUTION
Avatar of Kevin Cross
Kevin Cross
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Avatar of bjeverett

ASKER

Thanks for the quick response, mwvisa. I was having a little trouble with the initialization, but you're example cleared things up.
Avatar of emce
emce

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 };
Thanks, emce.  Rectangular Array is what I meant as they are both definitely multidimensional. :)