Linq其中值在Array中

时间:2010-09-03 15:27:49

标签: c# linq

IEnumerable<string> periods = new string[] {"ABC", "JKD", "223A"};

var someData = from p in returns  
               from d in p.ReturnDet  
               where p.Year > 2009 
               where d.Period <is in periods array> 

如何选择句点数组中包含d.periods的值?

2 个答案:

答案 0 :(得分:35)

使用Contains方法。

var someData = from p in returns   
               from d in p.ReturnDet   
               where p.Year > 2009  
               where periods.Contains(d.Period);

答案 1 :(得分:3)

var someData = from p in returns  
      from d in p.ReturnDet  
                where p.Year > 2009 
                where periods.Contains(d.Period)