我定义了以下内容:
public ICollection<Item> Items { get; set; }
当我运行此代码时:
Items = _item.Get("001");
我收到以下消息:
Error 3
Cannot implicitly convert type
'System.Collections.Generic.IEnumerable<Storage.Models.Item>' to
'System.Collections.Generic.ICollection<Storage.Models.Item>'.
An explicit conversion exists (are you missing a cast?)
有人可以解释我在做什么错。我对Enumerable,Collections和ToList()之间的区别感到困惑
补充信息
在我的代码后面,我有以下内容:
for (var index = 0; index < Items.Count(); index++)
我可以将Items定义为IEnumerable吗?