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

CsharpProgrammingServer Side Programming

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;
raja
Published on 07-Aug-2018 11:08:23
Advertisements