Part of the answer is "for historical reasons".
The IEnumerable
interface has been around since .NET 1.1, whereas generics (and thus IEnumerable<T>
) were added in .NET 2. IEnumerable<T>
extends IEnumerable
, which was a sensible decision because it allows you to use an IEnumerable<T>
in code that was already written to take an IEnumerable
.
But that means that to implement IEnumerable<T>
(which includes the IEnumerator<T> GetEnumerator()
method) you also have to implement IEnumerable
(which includes the IEnumerator GetEnumerator()
method).
As Servy noted, it's not that big a deal, because you can just do this:
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
where the non-explicit implementation GetEnumerator
is the one whose return type is IEnumerator<T>
.