tags:

views:

52

answers:

3

I would like to have a LINQ statement that calls the property IsValid.
If all elements returned true, I want the statement to return true as well.
How can it be done?

A: 

I am not sure if this is what you are looking for, but take a look at this article. http://www.albahari.com/nutshell/predicatebuilder.aspx

Ryk
Interesting article. Not directly related to what I'm asking.
the_drow
+8  A: 
var allValid = myList.All(item => item.IsValid);
Ben M
+3  A: 

You need the Enumerable.All<TSource> method:

bool everythingsZen = anEnumerable.All(a => a.IsValid);
jball
IsValid is a "property", in the OP's question. This would mean "a => a.IsValid" (no method here).
Reed Copsey
True, correcting.
jball