c# - undefined number of Or-operation on List -


i have list n-entries. list<myclass> result

and have list n-filter options list<string> filters

what want return result list filtered other list.

for and-operation easy this:

foreach (var filter in filters)  {      results = results.where(x => x.result == filter); } 

but how code or-operation?

you can use wherein combination any in case:

results = results.where(x => filters.any(f => f == x.result)); 

https://msdn.microsoft.com/library/bb534972(v=vs.110).aspx

others ways:

//contains, see daxaholic's post results = results.where(x => filters.contains(x.result)); 

https://msdn.microsoft.com/library/bhkz42b3(v=vs.110).aspx

//list extension method 'exists' results = results.where(x => filters.exists(f => f == x.result)); 

https://msdn.microsoft.com/library/bfed8bca(v=vs.110).aspx


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -