Phương thức Type.GetArrayRank () trong C # lấy số thứ nguyên trong một mảng.
Cú pháp
public virtual int GetArrayRank ();
Bây giờ chúng ta hãy xem một ví dụ để triển khai phương thức Type.GetArrayRank () -
Ví dụ
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);
}
} Đầu ra
Điều này sẽ tạo ra kết quả sau -
Array Rank = 3
Bây giờ chúng ta hãy xem một ví dụ khác để triển khai phương thức Type.GetArrayRank () -
Ví dụ
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));
}
} Đầu ra
Điều này sẽ tạo ra kết quả sau -
Array Rank = 8 Are both types equal? True