How to check if all items in the true list are returned for a property using Linq?

I would like to have a LINQ statement that calls the IsValid property.
If all the elements are true, I want the operator to return true as well.
How can I do that?

+3
source share
3 answers
var allValid = myList.All(item => item.IsValid);
+12
source

You need the Enumerable.All <TSource> method:

bool everythingsZen = anEnumerable.All(a => a.IsValid);
+4
source

, . Enumerable.All true,

var allValid = myList.Any() && myList.All(item => item.IsValid);

Enumerable.All true ?

+3

Source: https://habr.com/ru/post/1752553/


All Articles