Array.Rank Property is used to get the rank of the Array. Rank is the number of dimensions of an array. For example, 1-D array returns 1, a 2-D array returns 2, and so on.
Syntax:
public int Rank { get; }Property Value: It returns the rank (number of dimensions) of the Array of type System.Int32.
Below programs illustrate the use of above-discussed property:
Example 1:
using System;
namespace geeksforgeeks {
class GFG {
public static void Main()
{
string[] weekDays;
weekDays = new string[] {"Sun", "Mon", "Tue", "Wed",
"Thu", "Fri", "Sat" };
Console.WriteLine("Dimension of weekDays array: "
+ weekDays.Rank);
}
}
}
|
Output:
Dimension of weekDays array: 1
Example 2:
using System;
namespace geeksforgeeks {
class GFG {
public static void Main()
{
int[, ] arr2d = new int[4, 2];
int[,, ] arr3d = new int[4, 2, 3];
int[][] jdarr = new int[2][];
Console.WriteLine("Dimension of arr2d array: "
+ arr2d.Rank);
Console.WriteLine("Dimension of arr3d array: "
+ arr3d.Rank);
Console.WriteLine("Dimension of jdarr array: "
+ jdarr.Rank);
}
}
}
|
Output:
Dimension of arr2d array: 2
Dimension of arr3d array: 3
Dimension of jdarr array: 1
Note:
Reference: