I’m writing a class that implements the interface IEnumerator. To get it to compile, I need the following two methods:
public object Current
{
get { return current; }
}
T IEnumerator<T>.Current
{
get { return current; }
}
Why are both of these necessary? On the surface, it looks like only the latter is needed.
That’s because
IEnumerator<T>implements theIEnumeratorinterface which is the non-generic version of the interface that existed before generics were introduced in .NET 2.0. So when implementing an interface (IEnumerator<T>in your case) you need to also implement all other interfaces that this interface implements.