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

前端 未结 6 2060
清酒与你
清酒与你 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:44

    Use GetLength(), rather than Length.

    int rowsOrHeight = ary.GetLength(0);
    int colsOrWidth = ary.GetLength(1);
    

提交回复
热议问题