How To Use C# Queue Class Fifo First-In, First-Out Enqueue Dequeue
How To Use C# Queue Class Fifo First-In, First-Out Enqueue Dequeue
The Queue works like FIFO system , a first-in, first-out collection of Objects. Objects stored
in a Queue are inserted at one end and removed from the other. The Queue provide additional
insertion, extraction, and inspection operations. We can Enqueue (add) items in Queue and
we can Dequeue (remove from Queue ) or we can Peek (that is we will get the reference of
first item ) item from Queue. Queue accepts null reference as a valid value and allows
duplicate elements.
Syntax : Queue.Enqueue(Object)
Object : The item to add in Queue
days.Enqueue("Sunday");
Dequeue : Remove the oldest item from Queue (we don't get the item later)
days.Dequeue();
Peek : Get the reference of the oldest item (it is not removed permanently)
days.peek();