
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Array Rank Property of Array Class in C#
Let us see an example to find the number of dimensions of an array, using the Rank property.
arr.Rank
Here, arr is our array −
int[,] arr = new int[5,5];
If you want to get the rows and columns the array 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[4,5]; Console.WriteLine(arr.GetLength(0)); Console.WriteLine(arr.GetLength(1)); 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
4 5 Upper Bound: 3 Lower Bound: 0 Dimensions of Array : 2
Advertisements