【发布时间】:2012-05-02 11:08:20
【问题描述】:
好的,我环顾四周,找不到答案。我有一个返回
的方法IEnumerable<ICar>
并且调用方法将方法的结果存储在
List<ICar>
但我收到以下错误。
System.Collections.Generic.IEnumerable<Test.Interfaces.ICar> to
System.Collections.Generic.List<Test.Interfaces.ICar>. An explicit conversion exists
(are you missing a cast?)
我在msdn上看了
IEnumerable<T> interface and List<T> class.
以下行来自 msdn。
public class List<T> : IList<T>, ICollection<T>, IEnumerable<T>, IList, ICollection,
IEnumerable
我只是不明白为什么我不能分配
IEnumerable<ICar> to List<ICar>.
谁能给我解释一下。我错过了什么。
【问题讨论】:
-
你试过在返回的对象上调用 ToList() 吗?
-
请不要在标题前加上“C#”。这就是标签的用途。