2011-02-28 128 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)); 

希望這有助於。