This method(comes under System.Collections namespace) is used to remove all the objects from the Stack. This method will set the Count of Stack to zero, and references to other objects from elements of the collection are also removed. This method is an O(n) operation, where n is Count.
public virtual void Clear ();
Below programs illustrate the use of above-discussed method:
Total number of elements in the Stack are : 6 Total number of elements in the Stack are : 0
Total number of elements in the Stack are : 5 Total number of elements in the Stack are : 0
- Difference between Method Overriding and Method Hiding in C#
- Extension Method in C#
- C# | IndexOfAny() Method
- C# | Dictionary.Add() Method
- C# | Uri.GetHashCode() Method
- C# | Join Method | Set - 2
- C# | Math.Exp() Method
- C# | StartsWith() Method
- C# | PadRight() Method
- C# | Method Overloading
- C# | Math.Pow() Method
- DateTime.Add() Method in C#
- Queue.Contains() Method in C#
- C# | Uri.IsWellFormedOriginalString() Method
- 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 firstname.lastname@example.org. 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.