如何找到一个二维数组的大小? [英] How do I find the size of a 2D array?
本文介绍了如何找到一个二维数组的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我宣布这个数组...
If I declare this array...
string[,] a = {
{"0", "1", "2"},
{"0", "1", "2"},
{"0", "1", "2"},
{"0", "1", "2"},
};
然后我可以测量长度
Then I can measure the length with
a.Length
这是12.我如何测量内阵列的尺寸?如果我尝试...
which is 12. How do I measure the dimension of the arrays within? If I try...
a[0].Length
我得到 []内索引数错误;预计2
。是什么给了?
推荐答案
您希望您的阵列对GetLength()方法:
You want the GetLength() method of your array:
a.GetLength(0);
<一个href=\"http://msdn.microsoft.com/en-us/library/system.array.getlength.aspx\">http://msdn.microsoft.com/en-us/library/system.array.getlength.aspx
这篇关于如何找到一个二维数组的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文