Enumerators

Chapter 8, discusses enumerators, a topic that is a natural extension of this chapter. Enumerators typically are used to iterate collections. Enumerators are implemented and typically exposed by an enumerable object. Enumerable objects implement the IEnumerable interface, where the IEnumerable.GetEnumerator method returns an enumerator object.

The foreach statement is the best known expression of enumeration in C#. The target of the foreach statement is not any object—it has to be an enumerable object.

The next chapter documents the enumerator pattern, including how to implement an enumerator and enumerable object.

Get Programming Microsoft® Visual C#® 2008: The Language now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.