Type.GetArrayRank() Method in C#


The Type.GetArrayRank() method in C# gets the number of dimensions in an array.

Syntax

public virtual int GetArrayRank ();

Let us now see an example to implement the Type.GetArrayRank() method −

Example

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);
   }
}

Output

This will produce the following output −

Array Rank = 3

Let us now see another example to implement the Type.GetArrayRank() method −

Example

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));
   }
}

Output

This will produce the following output −

Array Rank = 8 Are both types equal? True

Updated on: 04-Nov-2019

59 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements