【发布时间】:2013-03-01 10:17:59
【问题描述】:
在以下情况下如何重置 IEnumerator 实例? (e.Reset() 抛出 NotImplementedException)
void Main()
{
IEnumerator<string> e = new List<string> { "a", "b", "c" }.Select(o => o).GetEnumerator();
while( e.MoveNext() )
{
Console.WriteLine( e.Current );
}
if(
//some condition
)
{
e.Reset();
while( e.MoveNext() )
{
//Do something else with e.Current
}
}
}
【问题讨论】: