This question already has answers here:
How do you get the width and height of a multi-dimensional array?

(6个答案)


2年前关闭。




如果我声明这个数组...
string[,] a = {
                  {"0", "1", "2"},
                  {"0", "1", "2"},
                  {"0", "1", "2"},
                  {"0", "1", "2"},
              };

然后我可以用
a.Length

哪个是12。如何测量其中的数组的维数?如果我尝试...
a[0].Length

我得到Wrong number of indices inside []; expected 2。是什么赋予了?

最佳答案

您需要数组的GetLength()方法:

a.GetLength(0);

http://msdn.microsoft.com/en-us/library/system.array.getlength.aspx

10-08 04:22