Foreach with where clause?
5 answers
You can use method syntax
foreach(object obj in listofObjects.Where(obj => !obj.property))
The query syntax can also be used, but it is not readable (at least for me):
foreach(object obj in (from x in listofObjects where !x.property select x))
If you are going to use this, I would store the request in a variable:
var query = (from x in listofObjects
where !x.property
select x);
foreach(var obj in query) { }
+9
source to share