This method(comes under System.Collections namespace) is used to remove and returns the object at the top of the Stack. This method is similar to the Peek method, but Peek does not modify the Stack.
public virtual object Pop ();
Return Value: It returns the Object removed from the top of the Stack.
Exception : This method will give InvalidOperationException if the Stack is empty.
Below programs illustrate the use of the above-discussed method:
Number of elements in the Stack: 5 Top element of Stack is: GeeksforGeeks Number of elements in the Stack: 4
Number of elements in the Stack: 2 Top element of Stack is: 9 Number of elements in the Stack: 1
- Difference between Method Overriding and Method Hiding in C#
- C# | Clone() Method
- C# | Join Method | Set - 2
- Decimal.Add() Method in C#
- C# | Math.Exp() Method
- C# | Math.Pow() Method
- Main Method in C#
- C# | CompareOrdinal() Method
- TimeSpan.Add() Method in C#
- C# | Replace() Method
- C# | Insert() Method
- C# | Uri.IsHexEncoding() Method
- Anonymous Method in C#
- DateTimeOffset.Add() Method in C#
- C# | EndsWith() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.