Enqueue and Dequeue operations on Queue in C#.


Enqueue Operations : Enqueue Operations are used to insert elements into Queue.

Queue<int> queue = new Queue<int>();
queue.Enqueue(1);
queue.Enqueue(2);
queue.Enqueue(3);
//Display queue elements after Enqueue
foreach (int i in queue )
  {
     Console.WriteLine(i);
  }

Dequeue Operations : Dequeue Operations are used to remove elements from the Queue.

queue.Dequeue();
//Display queue elements after Dequeue
foreach (int i in queue)
  {
     Console.WriteLine(i);
  }


Peek Operation : Peek Operation is used to get the beginning element from the Queue.

int begin = queue.Peek();
//Display Peek element from the Queue
Console.WriteLine(begin);