Array.GetLength()
in C# is an array property. It is used to get the number of elements, or the length, of an array. It can be used to get the length of an array of any dimension.
public int Length { get; }
None. It is only called on an array.
The value returned is an integer value that is the total number of elements present in an array. It returns 0 if no elements are present.
// use Systemusing System;// using System.Collections.Generic;// create classpublic class ArrayClearance {// Main Methodpublic static void Main(){// Creating and initializing new the Stringint[] arr1 = {10, 20, 30, 40};char[] arr2 = {'E', 'd', 'p', 'r', 'e', 's', 's', 'o'};bool[] arr3 = {true, false};double[] arr4 = {};// print lenghts of arraysConsole.WriteLine(arr1.Length);Console.WriteLine(arr2.Length);Console.WriteLine(arr3.Length);Console.WriteLine(arr4.Length);}}
Length
property.