The exact opposite of All() is essentially None , but since LINQ does not have a None() method, you can accomplish the same result via !set.Any() .
!a_list.Any(item => !(item.matches == true))
This will result in true if none of the items in the a_list has matches , which is not true.
This double negative result is a bit confusing, therefore, to provide a simpler example:
names.All(item => item.StartsWith("R"))
true if all elements in names start with R (as you already know).
!names.Any(item => item.StartsWith("R"))
true if none of the elements in names start with R.
Based on your comment below, it sounds like you're just looking for a way to achieve the same result as your current code snippet, but in a different way. This should provide the same result as the current code, but without ! in the predicate:
!a_list.Any(item => item.matches == true)
This can be further simplified:
!a_list.Any(item => item.matches)
I would suggest that yours might be simplified, namely:
a_list.All(item => !item.matches)
There is rarely a good reason for explicitly comparing a boolean with true or false .
Jlrishe
source share