Marc Gravell escribió:
> Because IEnumerable<T> : IEnumerable, and you haven't implemented the
> non-generic form; just add:
[quoted text clipped - 3 lines]
> return GetEnumerator();
> }
Thanks! Now it works, but, now I don't understand why I need this cast:
public class TestGenericEnumerator<T> :
System.Collections.Generic.IEnumerable<T>
{
System.Collections.Generic.IEnumerator<T>
System.Collections.Generic.IEnumerable<T>.GetEnumerator()
{
return null;
}
System.Collections.IEnumerator
System.Collections.IEnumerable.GetEnumerator()
{
return (
//why is this cast needed!?
(IEnumerable<T>)
//end cast
this).GetEnumerator();
}
}
Thanks in advance.
Marc Gravell - 26 Jul 2007 21:20 GMT
> why is this cast needed!?
Because you switched the generic version to an explicit
implementation, and so there is no this.GetEnumerator()
If you want to do this, consider having a single private
implementation that both the generic and non-generic versions invoke:
private IEnumerator<T> GetEnumerator() {
return null; // the actual implementation
}
IEnumerator<T> IEnumerable<T>.GetEnumerator() {
return GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator() {
return GetEnumerator();
}