C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
C# Stack<T>C# Stack<T> class is used to push and pop elements. It uses the concept of Stack that arranges elements in LIFO (Last In First Out) order. It can have duplicate elements. It is found in System.Collections.Generic namespace. C# Stack<T> exampleLet's see an example of generic Stack<T> class that stores elements using Push() method, removes elements using Pop() method and iterates elements using for-each loop. using System; using System.Collections.Generic; public class StackExample { public static void Main(string[] args) { Stack Output: Sonoo Peter James Ratan Irfan Peek element: Irfan Pop: Irfan After Pop, Peek element: Ratan
Next TopicC# Queue
|