Implementation of C# Queue class
Program.cs
using System.Collections.Generic;

Queue<string> q = new Queue<string>();
q.Enqueue("Apple");
q.Enqueue("Cherry");
q.Enqueue("Apple");
q.Enqueue("Durian");

Console.Write("Queue elements: ");
foreach (string s in q)
{
    Console.Write(s + " ");
}

Console.WriteLine("\nFront element: " + q.Peek());
Console.WriteLine("Dequeue: element: " + q.Dequeue());
Console.WriteLine("Front element: " + q.Peek());
Console.WriteLine("Number of elements: " + q.Count);
Output
kodingwindow@kw:~/csharp$ dotnet run
Queue elements: Apple Cherry Apple Durian 
Front element: Apple
Dequeue: element: Apple
Front element: Cherry
Number of elements: 3
kodingwindow@kw:~/csharp$ 
Advertisement