如何找到二维数组的大小? [英] 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"},
};
然后我可以用
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);
http://msdn.microsoft.com/en-us/library/system.array.getlength.aspx
这篇关于如何找到二维数组的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文