Stack Push() 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 34 | class Program { static void Main(string[] args) { Stack colors = new Stack(); colors.Push("Blue"); colors.Push("DodgerBlue"); colors.Push("SkyBlue"); colors.Push("LightBlue"); colors.Push("DeepSkyBlue"); Console.WriteLine("Stack Elements... "); foreach (string color in colors) { Console.WriteLine(color); } colors.Push("MidnightBlue"); Console.WriteLine(); Console.WriteLine("After inserting an object at the top of the Stack"); Console.WriteLine("sing Push(object) 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 | Stack Elements... DeepSkyBlue LightBlue SkyBlue DodgerBlue Blue After inserting an object at the top of the Stack sing Push(object) method. Now Stack Elements... MidnightBlue DeepSkyBlue LightBlue SkyBlue DodgerBlue Blue |