我有这个疑问我的清单应包含哪些类型?
List<int> AuctionIds =
(from a in _auctionContext.Auctions
where a.AuctionEventId == auction.AuctionEventId
select new { a.Id }).ToList();
但是我收到一个编译错误
Cannot implicitly convert type 'System.Collections.Generic.List<AnonymousType#1>' to 'System.Collections.Generic.List<int>'
应该AuctionIds是什么类型的?
编辑
的AuctionIds场其实是在另一个类(模型类),所以我不能只用VAR。我不能相信Jon Skeet没有回答这个问题。
选择a.Id不起作用。 –
我不想使用var,因为我实际上有另一个类中的AuctionIds字段。 –
mmn ..我能想到的唯一方法是创建一个模型来存储您的数据。然后将该Model对象添加到列表中。 –