Container<ImplementerOfIInterface> is not Container<IInterface>. Why not?
- by Chris Simmons
Why wouldn't DoesntWork() work below? The error is:
Cannot implicitly convert type 'List' to 'IEnumerable'. An explicit conversion exists (are you missing a cast?). I know this is something about generic/templates I'm not getting, but List is IEnumerable and Implementer is an IInterface. I don't see why this needs to be casted (or if it really can be).
public interface IInterface
{
// ...
}
public class Implementer : IInterface
{
// ...
}
IEnumerable<IInterface> DoesntWork()
{
List<Implementer> result = new List<Implementer>();
return result;
}