Type.GetArrayRank() วิธีการใน C# รับจำนวนมิติในอาร์เรย์
ไวยากรณ์
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