C# Queue Dequeue

Description

Queue Dequeue removes and returns the object at the beginning of the Queue .

Syntax

Queue.Dequeue has the following syntax.


public T Dequeue()

Returns

Queue.Dequeue method returns The object that is removed from the beginning of the Queue.

Example


using System;//ww  w  .  j a v a  2  s  . 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 »
    System.Collections.Generic »




HashSet
LinkedList
LinkedListNode
List
Queue
SortedSet
Stack