Array.GetUpperBound Method (Int32)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets the index of the last element of the specified dimension in the array.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

member GetUpperBound : 
        dimension:int -> int

Parameters

dimension
Type: System.Int32

A zero-based dimension of the array whose upper bound needs to be determined.

Return Value

Type: System.Int32

The index of the last element of the specified dimension in the array, or -1 if the specified dimension is empty.

Exception Condition
IndexOutOfRangeException

dimension is less than zero.

-or-

dimension is equal to or greater than Rank.

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.

The following example uses the GetLowerBound and GetUpperBound methods to display the bounds of a one-dimensional and two-dimensional array and to display the values of their array elements.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show: