Returns the object at the head of the Stack without removing it.
[Visual Basic] Overridable Public Function Peek() As Object [C#] public virtual object Peek(); [C++] public: virtual Object* Peek(); [JScript] public function Peek() : Object;
The Object at the top of the Stack.
Exception Type | Condition |
---|---|
InvalidOperationException | The Stack has no elements. |
This method can be overridden by a derived class.
a null reference (in Visual Basic Nothing) 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 Count property or catch theInvalidOperationException, which is thrown when the Stack is empty.
Stack Class | Stack Members | System.Collections Namespace | Pop | Push