C# Queue ToArray

Description

Queue ToArray copies the Queue elements to a new array.

Syntax

Queue.ToArray has the following syntax.


public T[] ToArray()

Returns

Queue.ToArray method returns

Example


using System;// ww  w .ja  v a2s  . 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");

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

        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