积极答复者
如何用LinQ或Lambda筛选集合中的集合

问题
-
PartInfo类总包含FeatureInfo集合,我要从List<PartInfo>中筛选出所有的FamilyName,请问如何写LinQ或Lambda?
class PartInfo { public string PartName { get; set; } public string ModelName { get; set; } public List<FeatureInfo> Features { get; set; } public string UCCode { get; set; } public PartInfo() { Features = new List<FeatureInfo>(); } } class FeatureInfo { public string FaimlyName { get; set; } public string FeatureName { get; set; } public string FeatureValue { get; set; } }
Sonny.Lin
答案
全部回复
-
Hi qing2000,
有很多的语句可以实现。 比如,你可以检测该PartInfo对象中符合FamilyName的FeatureInfo个数,或者检测该PartInfo对象中是否有任意的FeatureInfo符合条件。
var v = pList.Where( pi => pi.Features.Where(f => f.FaimlyName == "name").Count()> 0).ToList(); var v2 = pList.Where( pi => pi.Features.Any(f => f.FaimlyName == "name")).ToList();
Bob Wu [MSFT]
MSDN Community Support | Feedback to us
- 已编辑 Bob Wu-MTModerator 2012年10月2日 3:20