Multi-dimensional arrays
GetUpperBound(), GetLowerBound() are the functions used to get the bound of a
array. These methods of the array class. You can use it with single dimension as well as
for multi-dimensional arrays.
GetLowerBound() is to get the upper limit of an array.
GetUpperBound is to get the lower limit of an array.
e.g.
string[] weeks = {"Monday", "Tuesday", "Wednesday", "Thursday",
"Friday",
"Saturday",
"Sunday"};
MessageBox.Show(weeks.GetUpperBound(0).ToString());
//the above statement returns 6 as the upper bound for the array weeks.
Syntax : arrayname.GetUpperBound/GetLowerBound(dimension)
Dimension refers to the which upper/lower bound should be found, 0 for first, 1 for
second and so on.
e.g.
string [,,] student_details = new string[10,20,15];
int upperlimit = 0;
// This will return 10 for the 1st row element
upperlimit = student_details.GetUpperBound(0);
MessageBox.Show(upperlimit.ToString());
// This will return 20 for the 2nd row of element
upperlimit = student_details.GetUpperBound(1);
MessageBox.Show(upperlimit.ToString());
For all GetLowerBound(dimension) it will return 0 as the base lower bound is zero in
.NET