我想从我创建的列表中获取特定的x项目。从列表中获取特定的x项目使用linq
List<Item> il = (List<Item>)(from i in AllItems
where i.Iid == item.Iid
select i).Take(Int32.Parse(item.amount));
我得到以下错误:
"Unable to cast object of type 'd__3a`1[AssetManagement.Entities.Item]' to type 'System.Collections.Generic.List`1[AssetManagement.Entities.Item]'."
岂是固定的,为什么会出现这种情况?
可以合并'Where'从来不喜欢和'Take'用['TakeWhile'] (http://msdn.microsoft.com/en-us/library/system.linq.enumerable.takewhile.aspx) – Default
@默认我不确定。这些项目可能不在枚举的开始处。 – EZI
ups。误读文档。你是对的 – Default