C# Queue Queue(IEnumerable)
Description
Queue
initializes
a new instance of the Queue
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.