Queue(T) Class represents a first-in, first-out collection of objects.
using System;
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());
Queue<string> queueCopy = new Queue<string>(numbers.ToArray());
foreach( string number in queueCopy )
{
Console.WriteLine(number);
}
string[] array2 = new string[numbers.Count * 2];
numbers.CopyTo(array2, numbers.Count);
Queue<string> queueCopy2 = new Queue<string>(array2);
foreach( string number in queueCopy2 )
{
Console.WriteLine(number);
}
Console.WriteLine(queueCopy.Contains("four"));
queueCopy.Clear();
Console.WriteLine("queueCopy.Count = {0}", queueCopy.Count);
}
}
Related examples in the same category