C# | Finding the index of first element in the array
GetLowerBound() Method is used to find the index of the first element of the specified dimension in the array.
Syntax:
public int GetLowerBound (int dimension);
Here, dimension is a zero-based dimension of the array whose lower bound needs to be determined.
Return Value: The return type of this method is System.Int32. This method returns the index of the first element of the specified dimension in the array.
Exception: This method will give IndexOutOfRangeException if the value of dimension is less than zero, or equal or greater than Rank.
Note:
- GetLowerBound(0) returns the starting index of the first dimension of the array, and GetLowerBound(Rank – 1) returns the starting index of the last dimension of the array.
- The GetLowerBound method always returns a value that indicates the index of the lower bound of the array, even if the array is empty.
- This method is an O(1) operation.
Below programs illustrate the use of GetLowerBound() Method:
Example 1:
// C# program to illustrate the GetLowerBound(Int32) // method in 1-D array using System; public class GFG { // Main method static public void Main() { // 1-D Array int[] value = {1, 2, 3, 4, 5, 6, 7}; // Get the index of the first element // in the given Array by using // GetLowerBound(Int32) method int myvalue = value.GetLowerBound(0); Console.WriteLine("Index: {0}", myvalue); } } |
Index: 0
Example 2:
// C# program to illustrate the GetLowerBound(Int32) // method when the array is empty using System; public class GFG { // Main method static public void Main() { // Empty 1-D Array int[] value = {}; // Get the index of the first element // in the given Array by using // GetLowerBound(Int32) method int myvalue = value.GetLowerBound(0); Console.WriteLine("Index: {0}", myvalue); } } |
Index: 0
Reference: https://docs.microsoft.com/en-us/dotnet/api/system.array.getlowerbound?view=netcore-2.1
Recommended Posts:
- C# | Finding the index of last element in the array
- 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# | Remove element at specified index of Collection<T>
- 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# | Gets or sets the element at the specified index in StringCollection
- C# | How to remove the element from the specified index of the List
- C# | Insert an element into Collection<T> at specified index
- C# | Insert an element into the ArrayList at the specified index
- C# | Copy StringCollection at the specified index of array
- C# | Copy StringDictionary to Array at the specified index
- C# | Copy ListDictionary to Array instance at the specified index
- C# | Copy OrderedDictionary elements to Array instance at the specified index
- C# | Copying the entire ArrayList to 1-D Array starting at the specified index
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. 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.



