// Namespace Declaration //File location : C:\BareBone_CSharp\Source_Code\Template using System; //csc test_stack3.cs using System.Collections; using System.Collections.Generic; // Peek : Returns the object at the top //of the Stack without removing it namespace test_stack2 { class CsharpTemplate { // Main begins program execution. static void Main(string[] str) { Stack stack1 = new Stack(); stack1.Push("1 =Jan"); stack1.Push("2 =Feb"); stack1.Push("3 =Mar"); stack1.Push("4 =Apr"); stack1.Push("5 =May"); IEnumerable c = stack1; foreach(Object obj in c) { Console.Write(obj + " "); } Console.WriteLine( ""); Console.WriteLine( "--POP -"); Console.WriteLine("POP this "+ stack1.Pop() + " "); foreach(Object obj in c) { Console.Write(obj + " " ); } Console.WriteLine( ""); Console.WriteLine( "--peek -"); Console.WriteLine("Peek This " + stack1.Peek() + " "); foreach(Object obj in c) { Console.Write(obj + " " ); } } } } // |