CSharp - Queue<T> and Queue

Introduction

Queue<T> and Queue are first-in, first-out (FIFO) data structures, providing methods to Enqueue and Dequeue.

A Peek method returns the element at the head of the queue without removing it.

Count property tells the count of elements before dequeuing.

The following is an example of using Queue<int>:

Demo

using System;
using System.Collections.Generic;
class MainClass//from  ww  w. j a v  a 2 s  . c  o  m
{
   public static void Main(string[] args)
   {
         var q = new Queue<int>();
         q.Enqueue (10);
         q.Enqueue (20);
         int[] data = q.ToArray();
         Console.WriteLine (q.Count);
         Console.WriteLine (q.Peek());
         Console.WriteLine (q.Dequeue());
         Console.WriteLine (q.Dequeue());
         Console.WriteLine (q.Dequeue());

   }
}

Result