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:
using System;
public class GFG {
static public void Main()
{
int [] value = {1, 2, 3, 4, 5, 6, 7};
int myvalue = value.GetLowerBound(0);
Console.WriteLine( "Index: {0}" , myvalue);
}
}
|
Example 2:
using System;
public class GFG {
static public void Main()
{
int [] value = {};
int myvalue = value.GetLowerBound(0);
Console.WriteLine( "Index: {0}" , myvalue);
}
}
|
Reference: https://docs.microsoft.com/en-us/dotnet/api/system.array.getlowerbound?view=netcore-2.1
Last Updated :
01 Feb, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...