Skip to content

Instantly share code, notes, and snippets.

@AndrewBarfield
Created April 30, 2012 09:09
Show Gist options
  • Save AndrewBarfield/2556740 to your computer and use it in GitHub Desktop.
Save AndrewBarfield/2556740 to your computer and use it in GitHub Desktop.
C#: System.Collections.Generic: Enumerating a Generic Queue
using System;
using System.Collections.Generic;
namespace GenericQueueEnumerator {
class Program {
static void Main(string[] args) {
// Initialize a new instance of Queue<string>
Queue<string> myQ = new Queue<string>();
// Add stings to the end of the Queue<string>
myQ.Enqueue( ".com" );
myQ.Enqueue( ".net" );
myQ.Enqueue( ".edu" );
myQ.Enqueue( ".mil" );
// Get an enumerator for myQ
Queue<string>.Enumerator qEnumerator = myQ.GetEnumerator();
// Iterate the Queue<string> and display the current element
while ( qEnumerator.MoveNext() ) {
Console.WriteLine( qEnumerator.Current );
}
// Allow user to read the Console
Console.Read();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment