对具有多个条件的IEnumerable对象进行运行时筛选

时间:2014-09-26 19:06:05

标签: c# .net linq ienumerable

我收集了IEnumerable<Person>

类型的PersonCollection

它包含:

  • 名称
  • 国家

还有一些收集,比如数组

Array CityList = {"Delhi","Goa",...}
Array CountryList = {"India","USA",...}
Array DistrictList = {"Acb","Xyz",...}

我想在

上应用过滤器
attribute City, Country & District 
of PersonCollection on the basic 
of CityList, CountryList & DistrictList.

说我有一个过滤器

Array CityList = {"Delhi",}
Array CountryList = {"USA","UK"}
Array DistrictList = {null}

然后我需要这些记录的过滤结果

City = Delhi
OR
Country = USA
OR 
Country = UK

获得所需结果的任何解决方案?

1 个答案:

答案 0 :(得分:0)

PersonCollection.Where(p =>
    CityList.Contains(p.City) ||
    CountryList.Contains(p.Country) ||
    DistrictList.Contains(p.District)
)