Posts

Showing posts with the label #C# #Stack

C# - Stack

  Stack   is a special type of collection that stores elements in LIFO style (Last In First Out). C# includes the generic   Stack<T>   and non-generic   Stack   collection classes. It is recommended to use the generic   Stack<T>   collection. Stack is useful to store temporary data in LIFO style, and you might want to delete an element after retrieving its value. Stack<T> Characteristics Stack<T>  is Last In First Out collection. It comes under  System.Collection.Generic  namespace. Stack<T>  can contain elements of the specified type. It provides compile-time type checking and doesn't perform boxing-unboxing because it is generic. Elements can be added using the  Push()  method. Cannot use collection-initializer syntax. Elements can be retrieved using the  Pop()  and the  Peek()  methods. It does not support an indexer. Creating a Stack You can create an object of the...