的範圍之外我有一個交錯數組聲明:C#交錯數組:數組問題
char[][] m = new char[10][];
後來,它被填充。
System.Text.StringBuilder s = new System.Text.StringBuilder(c);
for (int x = 0; x < 10; x++)
s.Append('=');
for (int x = 0; x < 10; x++) m[x] = s.ToString().ToCharArray();
如果我執行下面的操作,我得到第二維度中的錯誤:
Console.WriteLine(String.Format("width={0}", m.GetLength(0)));
Console.WriteLine(String.Format("height={0}", m.GetLength(1))); <---- ERROR HERE
任何想法?
它是一個鋸齒狀的數組,不是一個方形數組(你用'char [,] maz'聲明)。每個子陣列將具有不同的長度。你用'maz [index] .Length'檢查。 – Abion47
不要使用['GetLenght()'](https://msdn.microsoft.com/en-us/library/system.array.getlength(v = vs.110).aspx),而是['Length' ](https://msdn.microsoft.com/en-us/library/system.array.length(v = vs.110).aspx)第一個數組的單個項目。 – Sinatr