In C#, GetLowerBound(dimension) returns the smallest valid index for that dimension. For ordinary arrays created with new T[n], the lower bound is 0.
Some arrays created with Array.CreateInstance can start at a non-zero lower bound. Knowing lower and upper bounds keeps loops correct for those rare cases.
This is an instance member of System.Array. You call it on an array variable with a dot, such as arr.GetLowerBound(...). Arrays in C# have a fixed length after creation; use List<T> when the count must grow.
Syntax
Call GetLowerBound with the dimension index.
C#
int start = nums.GetLowerBound(0);
Call
What it does
nums.GetLowerBound(0)
Usually 0 for normal 1D arrays.
grid.GetLowerBound(1)
Lower bound of dimension 1.
Pair with GetUpperBound when looping non-zero-bound arrays.
Library declarations
C#
public int GetLowerBound(int dimension);
Parameters
Parameter
Description
dimension
Required. 0-based dimension index.
Return Value
Return Value
Description
int
First valid index for that dimension.
C# Examples
Example 1 — Lower Bound Is Zero
Show the common case for a normal array.
C#
using System;
class Program {
static void Main() {
int[] nums = { 1, 2, 3 };
Console.WriteLine(nums.GetLowerBound(0));
Console.WriteLine(nums.GetUpperBound(0));
}
}
Output
0
2
How It Works
Starts at 0. First index is 0.
Upper is 2. Last index for length 3.
Typical arrays. new T[n] always uses 0.
Loop style. for (i = 0; i < Length; i++) works.
Example 2 — Custom Lower Bound
CreateInstance with lower bound 5; indexes start at 5.
C#
using System;
class Program {
static void Main() {
Array arr = Array.CreateInstance(typeof(int), new int[] { 3 }, new int[] { 5 });
Console.WriteLine("Lower: " + arr.GetLowerBound(0));
Console.WriteLine("Upper: " + arr.GetUpperBound(0));
arr.SetValue(42, 5);
Console.WriteLine(arr.GetValue(5));
}
}
Output
Lower: 5
Upper: 7
42
How It Works
CreateInstance overload. Lengths and lower bounds arrays.
Lower 5. First valid index is 5, not 0.
Upper 7. Three slots: 5, 6, 7.
SetValue(42, 5). Writes the first slot.
Example 3 — Lower Bounds per Dimension
Both dimensions of a normal matrix start at 0.
C#
using System;
class Program {
static void Main() {
int[,] grid = new int[2, 2];
Console.WriteLine(grid.GetLowerBound(0) + "," + grid.GetLowerBound(1));
}
}
Output
0,0
How It Works
Two zeros. Both dimensions start at 0.
Normal new. Rectangular arrays from new use zero bounds.
Still query. Library code may call GetLowerBound defensively.
Upper next. See GetUpperBound for last indexes.
Frequently Asked Questions
The first valid index in a dimension. Usually 0.
Yes, when created with certain CreateInstance overloads, but it is uncommon.
Use GetUpperBound for that dimension.
Length is the count of elements, not the upper index + 1 when lower bound is non-zero.
Rarely. Know the API exists if you handle arbitrary Array instances.