Type.GetArrayRank() 方法(C# 中)


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

更新於: 2019 年 11 月 4 日

76 次瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始
廣告