Consider two iterator methods with the same bodies:
public static IEnumerable<int> It1() {
...
}
public static IEnumerator<int> It2() {
...
}
Is there any circumstance where calling It2
is different from calling It1.GetEnumerator()
?
Is there ever a good reason to define an iterator as IEnumerator<T>
over IEnumerable<T>
? The only one I can think of is when you are implementing IEnumerable<T>.GetEnumerator()
.
EDIT: By iterator methods I mean methods using yield return
and yield break
constructs.