tags:

views:

89

answers:

3

Book I’ learning from claims that intArray has two dimensions. But since calling intArray.GetLength(1) will result in an IndexoutOfRange exception, couldn’t we claim that unlike rectangular arrays, intArray isn’t really multidimensional and thus has only one dimension?

int[][] intArray=new int[3][];

thank you

EDIT: BTW - I understand the difference between rectangular and jagged arrays

+3  A: 

It does not have 2 dimensions. The syntax would be int[,] intArray;. This is a jagged array (an array that contains arrays. It's not square. For example, it might contain an array of size 2 and one of size 5.

Jouke van der Maas
I understand the difference between rectangular and jagged arrays, I'm just saying that my book refers to it as multidimensional
flockofcode
@flockofcode: Does the first sentence not answer your question?
musicfreak
It does. thank you all
flockofcode
A: 

That is a jagged array For a 2 dimensional array on which you can use getlength(1) see below

 int[,] intarray=new int[3,0];
 Console.WriteLine(intarray.GetLength(1));
josephj1989
+1  A: 

It's an array-of-arrays, or a jagged array. MSDN has an article explaining what they are, and how they're different.

Most notably, a true 2D array is always rectangular - i.e. every row has the same number of columns. A jagged array may not even have a "row" (i.e. another array) at a given index - if it's null - or it may have "rows" of varying length.

Pavel Minaev