【发布时间】:2019-07-05 16:40:31
【问题描述】:
当我编写这段代码时,它允许我
IEnumerable<object> creator = new List<string>();
但是当我写的时候
IEnumerable<object> creator = new List<int>();
它显示编译时错误:
错误 CS0266 无法隐式转换类型 'System.Collections.Generic.List' 到 'System.Collections.Generic.IEnumerable'。显式 存在转换(您是否缺少演员表?)
我不知道为什么会这样。
【问题讨论】:
-
您可以使用 ICollection 代替 IEnumerable。
-
对我来说也是第一种情况编译器错误!?
标签: c#