Can anyone explain IEnumerable and IEnumerator to me? [closed]
for example, when to use it over foreach? You don’t use IEnumerable “over” foreach. Implementing IEnumerable makes using foreach possible. When you write code like: foreach (Foo bar in baz) { … } it’s functionally equivalent to writing: IEnumerator bat = baz.GetEnumerator(); while (bat.MoveNext()) { bar = (Foo)bat.Current … } By “functionally equivalent,” I mean … Read more