【发布时间】:2010-06-12 14:05:56
【问题描述】:
为什么DoesntWork() 不能在下面工作?错误是:
Cannot implicitly convert type 'List' to 'IEnumerable'. An explicit conversion exists (are you missing a cast?)。我知道这是关于我没有得到的通用/模板的东西,但 List 是 IEnumerable 并且实施者 是一个 IInterface。我不明白为什么需要强制转换(或者如果真的可以)。
public interface IInterface
{
// ...
}
public class Implementer : IInterface
{
// ...
}
IEnumerable<IInterface> DoesntWork()
{
List<Implementer> result = new List<Implementer>();
return result;
}
【问题讨论】:
标签: c# inheritance interface