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 the IEnumerator interface 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With