为什么DoesntWork()
以下工作?错误是: Cannot implicitly convert type 'List' to 'IEnumerable'. An explicit conversion exists (are you missing a cast?)
。我知道这是关于通用/模板的东西我没有得到,但列表是IEnumerable和实施者是 IInterface。我不明白为什么这需要被铸造(或如果它真的可以)。容器<ImplementerOfIInterface>不是容器<IInterface>。为什么不?
public interface IInterface
{
// ...
}
public class Implementer : IInterface
{
// ...
}
IEnumerable<IInterface> DoesntWork()
{
List<Implementer> result = new List<Implementer>();
return result;
}