我有两个域实体列表,
第一个是项目列表,结构:
string ItemID;
string ItemName;
int Qty;
double price;
另一个是要约清单,结构:
int OfferID;
string ItemID;
int OfferPrice;
有两个这样的变量,
List<DomainEntities.Items> ItemList=new List<DomainEntities.Items>();
List<DomainEntities.Offers> OfferList=new List<DomainEntities.Offers>();
现在我想从包含OfferList.ItemID的ItemList.ItemID属性进行过滤,输出应为List。
如何进行过滤?谢谢!
你可以这样做
ItemList.Where(item => OfferList.Any(offer => offer.ItemID == item.ItemID)).ToList();
您也可以这样做(可能执行得更快)
ItemList.Join(OfferList, item => item.ItemID, offer => offer.ItemID, (item, offer) => item).ToList();
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句