VOOZH about

URL: https://www.geeksforgeeks.org/c-sharp/c-sharp-total-number-of-elements-present-in-an-array/

⇱ C# | Total number of elements present in an array - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

C# | Total number of elements present in an array

Last Updated : 11 Jul, 2025

Array.GetLength(Int32) Method is used to find the total number of elements present in the specified dimension of the Array. 
Syntax: 
 

public int GetLength (int dimension);


Here, dimension is a zero-based dimension of the Array whose length needs to be determined.
Return value: The return type of this method is System.Int32. This method return a 32-bit integer that represents the number of elements in the specified dimension.
Exception:This method will give IndexOutOfRangeException if the value of dimension is less than zero or if the value of dimension is equal to or greater than Rank.
Below given are some examples to understand the implementation in a better way: 
Example 1:


Output: 
The elements of myarray :
445
44
66
6666667
78
878
1
Total Elements: 7

 

Example 2:


Output: 
myarray1 and myarray2: False
myarray1 and myarray3: True

 

Reference: https://learn.microsoft.com/en-us/dotnet/api/system.array.getlength?view=netcore-2.1
 

Comment
Article Tags:

Explore