Remove and return the object at the beginning of the Queue in CSharp

Description

The following code shows how to remove and return the object at the beginning of the Queue.

Example


using System;/*from w ww .ja v  a  2s  .  c  o m*/
using System.Collections.Generic;

class Example
{
    public static void Main()
    {
        Queue<string> numbers = new Queue<string>();
        numbers.Enqueue("one");
        numbers.Enqueue("two");
        numbers.Enqueue("three");
        numbers.Enqueue("four");
        numbers.Enqueue("five");

        foreach( string number in numbers )
        {
            Console.WriteLine(number);
        }

        Console.WriteLine(numbers.Dequeue());
        Console.WriteLine(numbers.Peek());
        Console.WriteLine(numbers.Dequeue());

    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Collections »




ArrayList
BitArray
Collection
Comparer
HashSet
Hashtable
LinkedList
List
ListDictionary
OrderedDictionary
Queue
SortedList
SortedSet
Stack
StringCollection
StringDictionary