Home »
.Net »
C# Programs
C# program to find out the dimensions of an array
Here, we are going to learn how to find the dimensions of an array in C#?
Submitted by Nidhi, on August 22, 2020
Here we will find out the dimensions of the given array, it means if an array is a one-d array then dimension will be 1 and if an array is a two-d array then dimension will be 2. In C# the "Rank" property is used to return the dimension of the specified array.
Program:
The source code to find out the dimensions of the specified array is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.
//Program to find out the dimensions of an array in C#
using System;
class Demo
{
static void Main(string[] args)
{
int[] OneD = new int[10] ;
int[,] TwoD = new int[3, 3];
int[,,] ThreeD = new int[2,3, 3];
Console.WriteLine("Dimensions of OneD array is : " + OneD.Rank);
Console.WriteLine("Demensions of TwoD array is : " + TwoD.Rank);
Console.WriteLine("Demensions of ThreeD array is : " + ThreeD.Rank);
}
}
Output:
Dimensions of OneD array is : 1
Demensions of TwoD array is : 2
Demensions of ThreeD array is : 3
Press any key to continue . . .
Explanation:
In the above program, we created three integer arrays OneD, TwoD, and ThreeD, and then we find out the dimensions of arrays using "Rank" property.
C# Basic Programs »