#555 – Enumerable Objects and Enumerators
April 5, 2012 1 Comment
An enumerable object is a type that represents a sequence of elements. The type implements either the IEnumerable or IEnumerable<T> interface, which means that it implements a GetEnumerator method, which is called to get the enumerator for the enumerable class.
An enumerator is an object that knows how to move through a sequence of elements. It implements either the IEnumerator or IEnumerator<T> interface, which means that it exposes a Current property that points to the current element in the sequence and a MoveNext method that moves to the next element.
You can think of an enumerator as a sort of pointer into a sequence of elements.
Enumerators, used on enumerable objects, are the internal mechanism that allows using a foreach statement to iterate through a collection of items.
Pingback: #560 – Returning an Enumerator from an Iterator « 2,000 Things You Should Know About C#