System.Array.GetUpperBound Method

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

Syntax

[System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.Success)]
public int GetUpperBound (int dimension)

Parameters

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

Returns

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

Exceptions

TypeReason
IndexOutOfRangeException

dimension < 0.

-or-

dimension is equal to or greater than the Array.Rank property of the current instance.

Remarks

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.

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0