Stack<T> Summary System.Stack<T> provides a LIFO (last in, first out) data structure. Description System.Stack<T> provides a LIFO (last in, first out) data structure. Examples Instantiation 123import System; auto stack = new System.Stack<int>(); Initialization with data 123import System; auto stack = new System.Stack<int>([ 1, 2, 3 ]); Comparison with System.Queue<T> 123456import System; auto stack = new System.Stack<int>([ 1, 2, 3 ]);auto queue = new System.Queue<int>([ 1, 2, 3 ]);Console.log(stack.pop()); // 3Console.log(queue.pop()); // 1 Methods clearClears the stack by removing all elements from the stack. isEmptyChecks if the stack is empty. lengthReturns the number of elements in the stack. peekReturns the most recently added element without removing it. popReturns and removes the most recently added element. pushAdds an element to the collection. Stack (Constructor)Constructs a System.Stack<T> object. toStringReturns a string representation of the stack. Share HTML | BBCode | Direct Link