Getting the dimensions of a multidimensional array

  • Thread starter Thread starter Durior
  • Start date Start date
D

Durior

A colleague has just showed me the [,] syntax that introduces
multidimensional arrays (as opposed to jagged arrays, which are similar
to C++ arrays).

So we defined such an array:
int[,] a= new [,]{{1,2},{3,4},{5,6}}
wonderful syntax, especially since "new" is used only once.

Anyhow, we were a little surprised to see that
a.Length
evaluates to 6.

That's logical in some way, but how can I find the max indices to be
used on each dimension? (in this case 3 and 2)
 
Durior said:
A colleague has just showed me the [,] syntax that introduces
multidimensional arrays (as opposed to jagged arrays, which are similar
to C++ arrays).

So we defined such an array:
int[,] a= new [,]{{1,2},{3,4},{5,6}}
wonderful syntax, especially since "new" is used only once.

Anyhow, we were a little surprised to see that
a.Length
evaluates to 6.

That's logical in some way, but how can I find the max indices to be
used on each dimension? (in this case 3 and 2)

Yup - look at Array.GetLength(int dimension)
 
Back
Top