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 System using System; // using System.Collections.Generic; // create class public class ArrayClearance { // Main Method public static void Main() { // Creating and initializing new the String int[] arr1 = {10, 20, 30, 40}; char[] arr2 = {'E', 'd', 'p', 'r', 'e', 's', 's', 'o'}; bool[] arr3 = {true, false}; double[] arr4 = {}; // print lenghts of arrays Console.WriteLine(arr1.Length); Console.WriteLine(arr2.Length); Console.WriteLine(arr3.Length); Console.WriteLine(arr4.Length); } }
Length
property.RELATED TAGS
CONTRIBUTOR
View all Courses