c# - Chaining Linq Where clauses -
how chain ‘where’ clauses in linq according different variable states. e,g ; checkboxes age ranges (21-30, 31-40, 41-50, 51-60 , 60 >)
we have list<people>
‘people’ , , need filter according checked boxes. assuming list cannot ienumerable has been evaluated
apart doing this:
list<people> filteredpeople = new list<people>(); if(cb1.checked) filteredpeople = filteredpeople.union(people.where(intheirtwenties)) //assuming method intheir20s filters correct if(cb2.checked) filteredpeople = filteredpeople.union(people.where(intheirthirties)) ; //...and on
is there better way around this?
i bundle 1 where
statement , update intheirtwenties
methods take individual person this:
filteredpeople.where(x => (cb1.checked && intheirtwenties(x)) || (cb2.checked && intheirthirties(x)) ...);
Comments
Post a Comment