GetUpperBound() Method is used to find the index of the last element of the specified dimension in the array.
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:
Dimension: 2 Index: 4
- Finding the Index which Points Beyond the Last Element in C#
- C# | Finding the index of first element in the array
- Finding the Index of First Element of the Specified Sequence in C#
- Finding the End Index of the Specified Range in C#
- Finding the Start Index of the Specified Range in C#
- Creating an Index From the Specified Index at the Start of a Collection in C#
- Creating an Index From the End of a Collection at a Specified Index Position in C#
- C# | How to get the last occurrence of the element in the List that match the specified conditions
- LINQ | Element Operator | Last
- C# | Insert an element into the ArrayList at the specified index
- C# | Gets or Sets the element at the specified index in the List
- C# | Remove the element at the specified index of the ArrayList
- C# | How to remove the element from the specified index of the List
- C# | Insert an element into Collection<T> at specified index
- C# | Remove element at specified index of Collection<T>
- C# | Get or set the element at specified index in Collection<T>
- C# | Get or set the element at the specified index in ArrayList
- C# | Gets or sets the element at the specified index in StringCollection
- Finding all the Elements of a Range from Start to End in C#
- C# | Copy StringCollection at the specified index of array
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.