VOOZH about

URL: https://www.geeksforgeeks.org/c-sharp/c-sharp-finding-the-index-of-last-element-in-the-array/

⇱ C# | Finding the index of last element in the array - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

C# | Finding the index of last element in the array

Last Updated : 11 Jul, 2025
GetUpperBound() Method is used to find the index of the last element of the specified dimension in the array. Syntax:
public int GetUpperBound (int dimension);
Here, dimension is a zero-based dimension of the array whose upper bound needs to be determined. Return Value:The return type of this method is System.Int32. This method returns the index of the last element of the specified dimension in the array Or -1 if the specified dimension is empty. Exception: This method will give IndexOutOfRangeException if the value of dimension is less than zero, or equal or greater than Rank. Note: GetUpperBound(0) returns the last index in the first dimension of the array, and GetUpperBound(Rank - 1) returns the last index of the last dimension of the array. This method is an O(1) operation. Below programs illustrate the use of GetUpperBound() Method: Example 1:
Output:
Index: 6
Example 2:
Comment
Article Tags:

Explore