Figure 5 The
Compiler-generated Iterator
กก
public class MyCollection : IEnumerable<string>
{
public virtual IEnumerator<string> GetEnumerator()
{
GetEnumerator$0003__IEnumeratorImpl impl;
impl = new GetEnumerator$0003__IEnumeratorImpl;
impl.<this> = this;
return impl;
}
private class GetEnumerator$0003__IEnumeratorImpl :
IEnumerator<string>
{
public MyCollection <this>; // Back reference to the collection
string $_current;
// state machine members go here
string IEnumerator<string>.Current
{
get
{
return $_current;
}
}
bool IEnumerator<string>.MoveNext()
{
//State machine management
}
IDisposable.Dispose()
{
//State machine cleanup if required
}
}
}