C# Stack Clear
Description
Stack Clear
removes all objects from the Stack.
Syntax
Stack.Clear
has the following syntax.
public virtual void Clear()
Returns
Stack.Clear
method returns
Example
The following example shows how to clear the values of the Stack.
//from w w w . j a v a 2s.c om
using System;
using System.Collections;
public class SamplesStack {
public static void Main() {
Stack myStack = new Stack();
myStack.Push( "A" );
myStack.Push( "B" );
Console.WriteLine( " Count : {0}", myStack.Count );
myStack.Clear();
foreach ( Object obj in myStack ){
Console.WriteLine( " {0}", obj );
}
}
}
The code above generates the following result.