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.
Syntax:
public virtual void Clear ();
Below programs illustrate the use of above-discussed method:
Example 1:
Output:
Total number of elements in the Stack are : 6
Total number of elements in the Stack are : 0
Example 2: