Javatpoint Logo
Javatpoint Logo

Type.GetArrayRank() Method in C#

In this article, we will discuss the Type.GetArrayRank() in C# with its syntax and examples.

What is the Type.GetArrayRank() method?

The Type.GetArrayRank() function in C# is a reflection method from the System namespace. This function is part of the Type class, which is required for inspecting and using type metadata in the Common Language Runtime (CLR). GetArrayRank() is used to determine the rank (dimensionality) of an array.

Basics of C# Arrays

Arrays are basic data structures that hold items of the same type in adjacent memory regions. Arrays may be single-dimensional, multidimensional, or jagged. A single-dimensional array is basically a vector, but a multidimensional array may contain more than two dimensions.

Introduction to the Type Class

The Type class is part of the .NET Framework and contains an advanced set of methods for accessing type-related data at runtime. It is often used in reflection, which allows the computer to inspect and communicate with types dynamically.

The GetArrayRank() function is specialized to array types. It helps us to identify the rank or number of dimensions of a specific array type. It is particularly useful when dealing with arrays of varied sizes, and the program must adjust its behavior appropriately.

Syntax:

It has the following syntax:

Return Value: This function returns an integer representing the number of dimensions in the present type.

Exception: This function throws an ArgumentException if the current type does not correspond to an array.

Example 1:

Let us take an example to illustrate the Type.GetArrayRank() method in C#.

Output:

The ArrayRank is: 8

Example 2:

Let us take another example to illustrate the Type.GetArrayRank() method in C#.

Output:

The type is not in the given array
The Exception is Thrown: System.ArgumentException






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA




news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news