How to use the GetLength method of array class in C#?


The GetLength gets a 32-bit integer that represents the number of elements in the specified dimension of the Array.

First, set the array.

int[,] arr = new int[20, 30];

For a specified dimension of the array, set the index in the GetLength() method like −

Arr.GetLength(1);

Example

 Live Demo

using System;
class Program {
   static void Main() {
      int[,] arr = new int[20, 30];
      int len = arr.GetLength(1);
      Console.WriteLine(len);
   }
}

Output

30

Updated on: 23-Jun-2020

539 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements