C# 中三维数组的大小

csharpprogrammingserver side programming更新于 2025/9/21 11:52:17

要在 C# 中获取三维数组的大小,请使用 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];
      // 维度的长度
      Console.WriteLine(arr.GetLength(0));
      Console.WriteLine(arr.GetLength(1));
      Console.WriteLine(arr.GetLength(2));
      // 长度
      Console.WriteLine(arr.Length);
   }
}

输出

3
4
5
60

相关文章