using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CSharpStackDemo { class Program { static void Main(string[] args) { //Stack = LAST IN FIRST OUT (LIFO) //Initialize a stack Object Stack intStack = new Stack(); // Populate the Stack by using the "Push" method for (int i = 0; i < 5; i++) { intStack.Push((i + 1) * 10); } Console.WriteLine("Here are the items in the Stack: "); //Print each member of the Stack foreach (int i in intStack) { Console.Write("{0} ", i.ToString()); } // Displays the topmost member of the Stack without removing it Console.Write("\nThe value of the topmost member is: {0} \n", intStack.Peek().ToString()); // Removes the topmost item from the Stack and displays the remaining items intStack.Pop(); Console.Write("The topmost item has now been removed. \nNow the remaining members are: "); //Print each member of the Stack foreach (int i in intStack) { Console.Write("{0} ", i.ToString()); } System.Console.ReadKey(); } } }