Giffyguy Giffyguy - 1 year ago 69
C# Question

How do you get the width and height of a multi-dimensional array?

I have an array defined:

int [,] ary;
// ...
int nArea = ary.Length; // x*y or total area

This is all well and good, but I need to know how wide this array is in the
dimensions individually. Namely, they
might return 12 - but does that mean the array is 4 high and 3 wide, or 6 high and 2 wide?

How can I retrieve this information?

Answer Source

You use Array.GetLength with the index of the dimension you wish to retrieve.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download