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...
这是12。如何测量数组的维数?如果我试着…
a[0].Length
I get Wrong number of indices inside []; expected 2
. What gives?
我在[]中得到了错误的索引数;预计2。到底发生了什么事?
3 个解决方案
#1
90
You want the GetLength() method of your array:
你想要你的数组的GetLength()方法:
a.GetLength(0);
http://msdn.microsoft.com/en-us/library/system.array.getlength.aspx
http://msdn.microsoft.com/en-us/library/system.array.getlength.aspx
#2
60
Use Array.Rank
to get number of dimensions and then use Array.GetLength(int dimension)
to get the length of a specific dimension.
使用数组。秩以获得维数,然后使用数组。获取特定维度的长度。
#1
90
You want the GetLength() method of your array:
你想要你的数组的GetLength()方法:
a.GetLength(0);
http://msdn.microsoft.com/en-us/library/system.array.getlength.aspx
http://msdn.microsoft.com/en-us/library/system.array.getlength.aspx
#2
60
Use Array.Rank
to get number of dimensions and then use Array.GetLength(int dimension)
to get the length of a specific dimension.
使用数组。秩以获得维数,然后使用数组。获取特定维度的长度。