0% found this document useful (0 votes)
30 views

How To Use C# Queue Class Fifo First-In, First-Out Enqueue Dequeue

The Queue class in C# implements a first-in, first-out (FIFO) collection that allows adding items to one end and removing them from the other. It supports operations like Enqueue to add objects, Dequeue to remove the oldest object, and Peek to view the oldest object without removing it. Queues accept null values and duplicates, and common uses are to Enqueue items, then Dequeue or Peek them in FIFO order.

Uploaded by

Souky Brt
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

How To Use C# Queue Class Fifo First-In, First-Out Enqueue Dequeue

The Queue class in C# implements a first-in, first-out (FIFO) collection that allows adding items to one end and removing them from the other. It supports operations like Enqueue to add objects, Dequeue to remove the oldest object, and Peek to view the oldest object without removing it. Queues accept null values and duplicates, and common uses are to Enqueue items, then Dequeue or Peek them in FIFO order.

Uploaded by

Souky Brt
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

How to use C# Queue Class

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.

Some important functions in the Queue Class are follows :

Enqueue : Add an Item in Queue


Dequeue : Remove the oldest item from Queue

Peek : Get the reference of the oldest item

Enqueue : Add an Item in Queue

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)

Syntax : Object Queue.Dequeue()


Returns : Remove the oldest item and return.

days.Dequeue();

Peek : Get the reference of the oldest item (it is not removed permanently)

Syntax : Object Queue.Peek()


returns : Get the reference of the oldest item in the Queue

days.peek();

You might also like