![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do you find the number of dimensions of an array in C#?
To find the number of dimensions of an array, use the Rank property.
arr.Rank
Here, arr is our array −
int[,] arr = new int[3,4];
If you also want to get the rows and columns it has, then use the GetLength property −
arr.GetLength(0); arr.GetLength(1);
The following is the complete code −
Example
using System; class Program { static void Main() { int[,] arr = new int[3,4]; Console.WriteLine(arr.GetLength(0)); Console.WriteLine(arr.GetLength(1)); // Length Console.WriteLine(arr.Length); Console.WriteLine("Upper Bound: {0}",arr.GetUpperBound(0).ToString()); Console.WriteLine("Lower Bound: {0}",arr.GetLowerBound(0).ToString()); Console.WriteLine("Dimensions of Array : " + arr.Rank); } }
Output
3 4 12 Upper Bound: 2 Lower Bound: 0 Dimensions of Array : 2
Advertisements