C# Simplified, part 3 - Using Array.Rank
(Page 5 of 6 )
You can programmatically determine the dimension of an array by using the Array.Rank property. Listing 3.9 illustrates the usage of this property in detail:
Listing 3.9
using System;
class ArrayRank
{
int[] SD;
int[,] MD;
int[,,] TD;
ArrayRank()
{
SD = new int[10];
MD = new int[10,20];
TD = new int[10,20,30];
}
void display()
{
Console.WriteLine("SD = {0}",SD.Rank);
Console.WriteLine("MD = {0}",MD.Rank);
Console.WriteLine("TD = {0}",TD.Rank);
}
public static void Main()
{
ArrayRank ar = new ArrayRank ();
ar.display();
}
}
In the above code, a method named display() is created and called by creating an object of the class.
Next: Enumerations >>
More C# Articles
More By Anand Narayanaswamy