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

csharpprogrammingserver side programming

C# 中的 GetLongLength 方法获取一个 64 位整数,该整数表示数组指定维度中的元素数量。

首先,设置数组。

long[,] arr2= new long[15, 35];

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

long len2 = arr2.GetLongLength(0);

让我们看一下完整的例子。

示例

using System;
class Program {
   static void Main() {
      int[,] arr = new int[20, 30];
      int len = arr.GetLength(0);
      Console.WriteLine(len);
      long[,] arr2= new long[15, 35];
      long len2 = arr2.GetLongLength(0);
      Console.WriteLine(len2);
   }
}

输出

20
15

相关文章