C# Queue GetEnumerator
Description
Queue GetEnumerator
returns an enumerator that iterates
through the Queue.
Syntax
Queue.GetEnumerator
has the following syntax.
public virtual IEnumerator GetEnumerator()
Returns
Queue.GetEnumerator
method returns An IEnumerator for the Queue.
Example
/*from w ww .j a v a 2 s .c om*/
using System;
using System.Collections;
public class SamplesQueue {
public static void Main() {
Queue myQ = new Queue();
myQ.Enqueue( "1" );
myQ.Enqueue( "2" );
myQ.Enqueue( "3" );
myQ.Enqueue( "4" );
myQ.Enqueue( "5" );
IEnumerator e = myQ.GetEnumerator();
while (e.MoveNext())
{
Object obj = e.Current;
Console.WriteLine(obj);
}
}
}
The code above generates the following result.