Ich war mit yield
und IEnumerable
Herumspielen und ich bin jetzt gespannt, warum oder wie das folgende Snippet funktioniert:Wie ist die Ausbeute aufzählbar?
public class FakeList : IEnumerable<int>
{
private int one;
private int two;
public IEnumerator<int> GetEnumerator()
{
yield return one;
yield return two;
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
Nun, wie sich dies der Compiler drehen:
public IEnumerator<int> GetEnumerator()
{
yield return one;
yield return two;
}
in ein IEnumerator<int>
?
http://csharpindepth.com/Articles/Chapter6/IteratorBlockImplementation.aspx –
Compiler Magie! – RBarryYoung