C# 中陣列的三維尺寸


要獲取 C# 中 3D 陣列的大小,請將其 `GetLength()` 方法與維度索引一起作為引數使用。

GetLength(dimensionIndex)

要獲取大小。

arr.GetLength(0)
arr.GetLength(1)
arr.GetLength(2)

示例

 即時演示

using System;
class Program {
   static void Main() {
      int[,,] arr = new int[3,4,5];
      // length of a dimension
      Console.WriteLine(arr.GetLength(0));
      Console.WriteLine(arr.GetLength(1));
      Console.WriteLine(arr.GetLength(2));
      // length
      Console.WriteLine(arr.Length);
   }
}

輸出

3
4
5
60

更新日期: 23-6-2020

1000+ 瀏覽

啟動你的 職業生涯

透過完成課程獲得認證

開始
廣告