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.






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.