
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
How to define the rank of an array in C#?
To find the number of dimensions of an array, use the Array Rank property. This is how you can define it −
arr.Rank
Here, arr is our array −
int[,] arr = new int[3,4];
If you want to get the rows and columns it has, then uses 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("Dimensions of Array : " + arr.Rank); } }
Output
3 4 12 Dimensions of Array : 2
- Related Articles
- How to define an array in C#?
- Rank of All Elements in an Array using C++
- How to find the Rank of a given Array in C#?
- How to define an array class in C#?
- How to find the length and rank of a jagged array in C#?
- How to define an array size in java without hardcoding?
- Get rank of a three-dimensional array in C#
- How to find the rank of a matrix in R?
- How to get the rank of a matrix in PyTorch?
- How to find percentile rank for groups in an R data frame?
- Replace the Array Elements by Its Corresponding Rank in Java
- How to define a rectangular array in C#?
- Applying rank filter to an image using the Pillow library
- How to calculate rank percentile of a list in Excel?
- Return matrix rank of array using Singular Value Decomposition method in Python

Advertisements