2011-02-28 125 views

回答

3

的对GetLength方法可用于返回一个阵列的维度

moreInts.GetLength(0); 
moreInts.GetLength(1); 
moreInts.GetLength(2); 

这是一个阵列的正确方式声明[,,]的大小。对于声明了[] [] []的数组,每个数组可以有不同的维数,KeithS的方法是正确的。

+0

+1,谢谢。我错过了.GetLength()接受了一个参数,这就是该函数的参数(认为它只是返回与.Length相同的东西,即9)。非常感激。 – jmq 2011-03-01 00:18:40

0

尝试使用此代码片段:

int[, ,] moreInts = { { { 10, 20, 30 }, { 60, 70, 80 }, { 111, 222, 333 } } }; 

List<int> indicies = new List<int>(); 

for (int i = 0; i < moreInts.Rank; i++) 
    indicies.Add(moreInts.GetUpperBound(i) + 1); 

indicies.ForEach(i => Console.WriteLine(i)); 

希望这有助于。