System.Collections.Stack.Peek Method

Returns the object at the top of the Stack without removing it.

Syntax

public virtual object Peek ()

Returns

The object at the top of the Stack.

Remarks

This method is similar to the Stack.Pop method, but Stack.Peek does not modify the Stack.

null can be pushed onto the Stack as a placeholder, if needed. To distinguish between a null value and the end of the stack, check the Stack.Count property or catch the InvalidOperationException, which is thrown when the Stack is empty.

This method is an O(1) operation.

Requirements

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