Excellent answer by crazycomputers.
Just thought I'd add that the reason the compiler complains when you don't include the second GetEnumerator() method is that the IEnumerable<T> generic interface itself inherits the IEnumerable non-generic interface. When you implement an interface you must also implement any interface that interface inherits. Both of these interfaces declare a GetEnumerator() method. That means it is necessary to provide an implementation of IEnumerable<T>.GetEnumerat
Main Topics
Browse All Topics





by: crazycomputersPosted on 2007-06-11 at 19:23:14ID: 19263247
The use is that by implementing both IEnumerable`1 (the generic interface) and IEnumerable, the object can be used by APIs that need an IEnumerable instance. It's more for backwards compatibility.
)) as opposed to implicit (public IEnumerator GetEnumerator()) does make the method private, but it can still be accessed by casting to IEnumerable:
Note that using an explicit interface implementation (IEnumerator IEnumerable.GetEnumerator(
((IEnumerable) this).GetEnumerator();
For example.