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

前端 未结 6 2053
清酒与你
清酒与你 2020-11-27 13:48

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

6条回答
  •  天涯浪人
    2020-11-27 14:31

    You could also consider using getting the indexes of last elements in each specified dimensions using this as following;

    int x = ary.GetUpperBound(0);
    int y = ary.GetUpperBound(1);
    

    Keep in mind that this gets the value of index as 0-based.

提交回复
热议问题