How do you find the length of an array in C#?



To find the length of an array, use the Array.Length() method.

Example

Let us see an example −

 Live Demo

using System; class Program {    static void Main(){       int[] arr = new int[10];       // finding length       int arrLength = arr.Length;       Console.WriteLine("Length of the array: "+arrLength);    } }

Output

Length of the array: 10

Above, we have an array −

int[] arr = new int[10];

Now to find the length, we used the Length() method −

int arrLength = arr.Length;
Updated on: 2020-06-20T10:48:01+05:30

18K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements