In the implementation of GetEnumerator() below, the compiler refuses to convert List<T>.Enumerator
to IEnumerator<Shape>
even though T is constrained by Shape. (1) Why is this, and (2) is there a workaround I'm overlooking?
using System.Collections.Generic;
interface Shape {
void Draw();
}
class Picture<T> : IEnumerable<Shape> where T : Shape {
List<T> shapes;
public IEnumerator<Shape> GetEnumerator()
{
return shapes.GetEnumerator();
}
}