C# Queue Enqueue
Description
Queue
adds an object to the end of the Queue
Syntax
Queue.Enqueue
has the following syntax.
public void Enqueue(
T item
)
Parameters
Queue.Enqueue
has the following parameters.
item
- The object to add to the Queue. The value can be null for reference types.
Example
using System;/*from w ww .ja v a2s . 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);
}
Console.WriteLine(numbers.Dequeue());
Console.WriteLine(numbers.Peek());
Console.WriteLine(numbers.Dequeue());
}
}
The code above generates the following result.