C# Array Rank
Description
Array Rank
gets the rank (number of dimensions) of the
Array. For example, a one-dimensional array returns 1, a two-dimensional
array returns 2, and so on.
Syntax
Array.Rank
has the following syntax.
public int Rank { get; }
Example
The following example initializes a one-dimensional array, a two-dimensional array, and a jagged array, and retrieves the Rank property of each.
using System;/*from w w w .j a v a 2s .c om*/
public class Example
{
public static void Main()
{
int[] array1 = new int[10];
int[,] array2= new int[10,3];
int[][] array3 = new int[10][];
Console.WriteLine("{0}: {1} dimension(s)",
array1.ToString(), array1.Rank);
Console.WriteLine("{0}: {1} dimension(s)",
array2.ToString(), array2.Rank);
Console.WriteLine("{0}: {1} dimension(s)",
array3.ToString(), array3.Rank);
}
}
The code above generates the following result.