C# Queue Queue(IEnumerable)

Description

Queue Queue (IEnumerable ) initializes a new instance of the Queue class that contains elements copied from the specified collection and has sufficient capacity to accommodate the number of elements copied.

Syntax


public Queue(
  IEnumerable<T> collection
)

Parameters

  • collection - The collection whose elements are copied to the new Queue .

Example


using System;//w  w w.j  a va 2  s  . c om
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");

        Queue<string> queueCopy = new Queue<string>(numbers.ToArray());

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

The code above generates the following result.





















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




HashSet
LinkedList
LinkedListNode
List
Queue
SortedSet
Stack