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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -