Removes and returns the object at the top of the Stack.
[Visual Basic] Overridable Public Function Pop() As Object [C#] public virtual object Pop(); [C++] public: virtual Object* Pop(); [JScript] public function Pop() : Object;
The Object removed from the top of the Stack.
Exception Type | Condition |
---|---|
InvalidOperationException | The Stack has no elements. |
This method can be overridden by a derived class.
Stack is implemented as a circular buffer. Push is an O(n) operation; Pop is an O(1) operation.
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.
The following example shows a null value inserted into a stack and then retrieved.
Stack s = new Stack (); s.Push ("Red"); s.Push ("Green"); s.Push (null); s.Push ("Blue"); s.Push ("Green"); String sc; while (s.Count > 0) { sc = (string) s.Pop(); Console.WriteLine (sc); }
Stack Class | Stack Members | System.Collections Namespace | Peek | Push