C# 中的 Type.GetArrayRank() 方法
csharpprogrammingserver side programming更新于 2025/9/25 9:37:17
C# 中的 Type.GetArrayRank() 方法用于获取数组的维数。
语法
public virtual int GetArrayRank ();
现在让我们看一个实现 Type.GetArrayRank() 方法的示例 −
示例
using System;
public class Demo {
public static void Main(string[] args) {
Type type = typeof(int[,, ]);
int arrRank = type.GetArrayRank();
Console.WriteLine("Array Rank = {0}", arrRank);
}
}
输出
这将产生以下输出 −
Array Rank = 3
现在让我们看另一个实现 Type.GetArrayRank() 方法的示例 −
示例
using System;
public class Demo {
public static void Main(string[] args) {
Type type = typeof(string[,,,,,,, ]);
Type type2 = typeof(string[,,,,,,, ]);
int arrRank = type.GetArrayRank();
Console.WriteLine("Array Rank = {0}", arrRank);
Console.WriteLine("Are both types equal? {0}", type.Equals(type2));
}
}
输出
这将产生以下输出 −
Array Rank = 8 Are both types equal? True

