如何找到二维数组的大小?
如果我声明这个数组...
string[,] a = {
{"0", "1", "2"},
{"0", "1", "2"},
{"0", "1", "2"},
{"0", "1", "2"},
};
那么我可以测量长度为
a.Length
12。如何测量其中数组的维度?如果我尝试...
a[0].Length
我会得到[]内的索引数量错误;预计2。什么给?
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
which is 12. How do I measure the dimension of the arrays within? If I try...
a[0].Length
I get Wrong number of indices inside []; expected 2
. What gives?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要数组的 GetLength() 方法:
http://msdn.microsoft.com /en-us/library/system.array.getlength.aspx
You want the GetLength() method of your array:
http://msdn.microsoft.com/en-us/library/system.array.getlength.aspx
使用
Array.Rank
获取维数,然后使用Array.GetLength( int size)
获取特定维度的长度。Use
Array.Rank
to get number of dimensions and then useArray.GetLength(int dimension)
to get the length of a specific dimension.使用 System.Array.GetLength(int 维度)。
Use System.Array.GetLength(int dimension).