Information Technology Reference
In-Depth Information
The IEnumerable<T> Interface
The generic
IEnumerable<T>
interface is very similar to the non-generic version,
IEnumerable
. The
generic
version
derives from
IEnumerable
, so it must also implement the
IEnumerable
interface.
Like
IEnumerable
, the generic version also contains a single member, a method called
GetEnumerator
. This version of
GetEnumerator
, however, returns a class object imple-
menting the generic
IEnumerator<T>
interface.
Since the class must implement two
GetEnumerator
methods, you should explicitly
implement the non-generic version, and implement the generic version in the class
itself, as shown in Figure 20-7.
Figure 20-7 illustrates the implementation of the interface.
Figure 20-7.
Implementing the IEnumerable<T> interface