Linq Where value is in Array

2020-02-27 06:19发布

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> 

How do I select values where the d.periods are contained in the periods array?

标签: c# linq
2条回答
forever°为你锁心
2楼-- · 2020-02-27 06:36

Use the Contains method.

var someData = from p in returns   
               from d in p.ReturnDet   
               where p.Year > 2009  
               where periods.Contains(d.Period);
查看更多
贪生不怕死
3楼-- · 2020-02-27 06:40
var someData = from p in returns  
      from d in p.ReturnDet  
                where p.Year > 2009 
                where periods.Contains(d.Period)
查看更多
登录 后发表回答