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 where
in 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));
Comments
Post a Comment