using System;
using System.Collections.Generic;
using System.Text;

public class MyClass
{

public static void PrintValues(IEnumerable<Int32> myCollection)
{
IEnumerator<Int32> myEnumerator = myCollection.GetEnumerator();
while(myEnumerator.MoveNext())
{
Console.WriteLine(myEnumerator.Current);
}

}

public static void RunSnippet()
{
Queue<Int32> intQueue = new Queue<Int32>();
for(int i=0 ; i < 5; i++)
intQueue.Enqueue(i*5);
PrintValues(intQueue);
Console.WriteLine(intQueue.Peek());
Console.WriteLine(intQueue.Peek());
}

#region Helper methods

public static void Main()
{
try
{
RunSnippet();
}
catch (Exception e)
{
string error = string.Format("---\nThe following error occurred while executing the snippet:\n{0}\n---", e.ToString());
Console.WriteLine(error);
}
finally
{
Console.Write("Press any key to continue...");
Console.ReadKey();
}
}

private static void WL(object text, params object[] args)
{
Console.WriteLine(text.ToString(), args);
}

private static void RL()
{
Console.ReadLine();
}

private static void Break()
{
System.Diagnostics.Debugger.Break();
}

#endregion
}

posted on 2015-11-10 15:20  jinweijie0527  阅读(143)  评论(0编辑  收藏  举报