thenth
thenth

Reputation: 491

Linq Where value is in Array

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?

Upvotes: 25

Views: 36087

Answers (2)

Adam Sills
Adam Sills

Reputation: 17062

Use the Contains method.

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

Upvotes: 39

Steve Danner
Steve Danner

Reputation: 22198

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

Upvotes: 3

Related Questions