Stacks normally operate on a LIFO system, Last in First out. There are three core stack commands, push, peek and pop. Push inserts an element at the top of the stack, peek returns the variable on top of the stack, and pop removes the top variable on the stack. I didn’t feel like coding one yet but you can your own stacks in a variety of ways, such as arrays or linked lists. This simple demonstration just uses the built-in Stack datatype of the C# library.

Stack<Int32> stack = new Stack<Int32>();
stack.Push(1); // Pushing 1 onto the stack
System.Console.WriteLine(stack.Peek()); // Top value on the stack.
stack.Push(2); // Pushing 2 onto the stack
System.Console.WriteLine(stack.Peek()); // Top value on the top of the stack - will be 2.
Int32 old = stack.Pop(); // Removing the top value and storing it into a variable.
System.Console.WriteLine(stack.Peek()); // Top value on the stack - will be 1.
System.Console.ReadLine();