如何在 C# 中使用数组类的 GetLength 方法?

csharpprogrammingserver side programming

GetLength 方法获取一个 32 位整数,表示数组指定维度的元素数量。

首先,设置数组。

int[,] arr = new int[20, 30];

对于数组的指定维度,请在 GetLength() 方法中设置索引,例如 −

Arr.GetLength(1);

示例

using System;
class Program {
   static void Main() {
      int[,] arr = new int[20, 30];
      int len = arr.GetLength(1);
      Console.WriteLine(len);
   }
}

输出

30

相关文章