C# Queue - c# - c# tutorial - c# net
What is Queue in C# ?
- C# Queue<T> class is used to Enqueue and Dequeue elements.
- It uses the concept of Queue that arranges elements in FIFO (First In First Out) order.
- It can have duplicate elements.
- It is found in System.Collections.Generic namespace.
Constructors:
- Queue<T> Constructor - Initializes a new instance of the Queue<T> class that is empty. The next lines shows how we create the empty queue.
- Queue<T> Constructor (IEnumerable<T>) - Initializes a new instance of the Queue<T>class that contains elements copied from the specified collection.
Queue
- Queue<T> Constructor (Int32) - Initializes a new instance of the Queue<T> class that is empty and has the specified initial capacity.
C# Queue<T> example:
- Let's see an example of generic Queue<T> class that stores elements using Enqueue() method, removes elements using Dequeue() method and iterates elements using for-each loop.