Stack Clear() Method
C# Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | class Program { static void Main(string[] args) { Stack colors = new Stack(); colors.Push("Magenta"); colors.Push("Maroon"); colors.Push("MediumSeaGreen"); colors.Push("Lavender"); Console.WriteLine("Stack Elements... "); foreach (string color in colors) { Console.WriteLine(color); } //this line remove all elements from Stack. colors.Clear(); Console.WriteLine("\nAfter Call Clear() Method, Stack Elements... "); foreach (string color in colors) { Console.WriteLine(color); } Console.ReadLine(); } } |
Output:
1 2 3 4 5 6 7 8 9 | Stack Elements... Lavender MediumSeaGreen Maroon Magenta After Call Clear() Method, Stack Elements... |