Generic Enumerators

Nongeneric enumerable objects and enumerators lack type specialty, which leads to performance problems and other issues. You can implement enumerable objects and enumerators using generic interfaces, which avoid some of the problems mentioned at the end of the previous section. Implement the IEnumerable<T> interface for generic enumerable objects. For generic enumerators, implement the IEnumerator<T> interface. Both IEnumerable<T> and IEnumerator<T> are generic interfaces found in the System.Collections.Generic namespace. IEnumerable<T> and IEnumerator<T> inherit their nongeneric counterparts IEnumerable and IEnumerator, respectively. This means the nongeneric methods must be implemented as well.

IEnumerable<T> Interface

Generic ...

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.