如何在C#中使用数组类的GetLength方法?
GetLength获取一个32位整数,该整数表示Array指定维中的元素数。
首先,设置数组。
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