Retrieving the size/dimensions of an array

cornelius1729

New member
Joined
Jan 21, 2009
Messages
4
Is there a simple way to retrieve the size of an array? For example:

If I declare a two dimensional integer array,

int[,] ia = { { 1, 2 }, { 3, 4 }, { 5, 6 } };

then I would like something like ia.Size, or ia.Dimensions that returns an integer array containing 3,2.

ia.Rank reveals that there are two dimensions, and ia.Length tells me that there are 6 elements, but I cant find what I want.

Thanks in advance.
 
Okay, I new it had to be obvious: you can iterate over the dimensions using GetLength, e.g.

int[] dims = new int[ia.Rank];
for(int i=0; i<ia.Rank; ++i)
{
dims = ia.GetLength(i);
}

Simple.
 
Back
Top