Created
April 30, 2012 09:09
-
-
Save AndrewBarfield/2556740 to your computer and use it in GitHub Desktop.
C#: System.Collections.Generic: Enumerating a Generic Queue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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