Multidimensional arrays, get dimensions at runtime

X

xxxxyz

Hi,

If I have multidimensional arrays can I get each dimansion at runtime?

For example if I have the array: int[,] a=new int[6,8];
I want to take 6 and 8 at runtime?

Thanks.
 
G

Guest

Hi,

Try

int[,] MyArraw = new int[2,6];

MyArraw.Lenght(0); //Returns 2
MyArraw.Lenght(1); //Returns 6

Cheers
Salva
 
M

Morten Wennevik

Hm, not familiar with Array.Length(int) as Array.Length is a property and
cannot accept parameters. You probably mean Array.GetLength(int). There
is also Array.GetUpperBound(int) which returns the last valid index in a
dimension.

int[,] MyArraw = new int[2,6];
MyArraw.GetUpperBound(0); //Returns 1
MyArraw.GetUpperBound(1); //Returns 5
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top