Stack Pop() 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 31 32 33 |
class Program { static void Main(string[] args) { Stack colors = new Stack(); colors.Push("Orange"); colors.Push("DarkOrange"); colors.Push("OrangeRed"); colors.Push("Salmon"); colors.Push("DarkSalmon"); colors.Push("LightSalmon"); Console.WriteLine("Stack Elements... "); foreach (string color in colors) { Console.WriteLine(color); } Console.WriteLine("\nRemove and get the object at the top of the Stack"); Console.WriteLine("using Pop() method...."); Console.WriteLine(colors.Pop().ToString()); Console.WriteLine("\nAfter Call Pop() Method, Now Stack Elements... "); foreach (string color in colors) { Console.WriteLine(color); } Console.ReadLine(); } } |
Output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
Stack Elements... LightSalmon DarkSalmon Salmon OrangeRed DarkOrange Orange Remove and get the object at the top of the Stack using Pop() method.... LightSalmon After Call Pop() Method, Now Stack Elements... DarkSalmon Salmon OrangeRed DarkOrange Orange |