IEnumerable, and its generic counterpart IEnumerable
The IEnumerable
interface (in the System.Collections
namespace) contains only a single member, the GetEnumerator()
method, which returns an IEnumerator
.
The generic counterpart to IEnumerable
, IEnumerable<T>
(added to the System.Collections.Generic
namespace in the .NET framework 2.0) also contains only a single member, the GetEnumerator()
method; this returns an IEnumerator<T>
.
Interaction with the IEnumerable<T>
interface is often done through extension methods, for example First()
, Last()
and Count()
.
It is possible to obtain a generic IEnumerable<T>
from an IEnumerable
by calling either of the extension methods Cast<T>()
, or OfType<T>()
, depending on the case.