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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.