C# Queue GetEnumerator

Description

Queue GetEnumerator returns an enumerator that iterates through the Queue .

Syntax

Queue.GetEnumerator has the following syntax.


public Queue<T>.Enumerator GetEnumerator()

Returns

Queue.GetEnumerator method returns An Queue.Enumerator for the Queue.

Example


using System;/*from   w  ww  .  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);
        }

    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Collections.Generic »




HashSet
LinkedList
LinkedListNode
List
Queue
SortedSet
Stack