In the world of LINQ, predicate operators express Boolean-valued truths about sequences and their elements. Operators such as
All should sound familiar to those who’ve learned basics of predicate logic. Other operators include
SequenceEqual (to compare two sequences) and
Contains (to ask membership questions about elements in sequences). Let’s take a look at all of those.
All and Any
Any evaluate a predicate for each of the elements in a given sequence. If all the elements pass the predicate,
All will return true. If some of the elements pass the predicate,
Any will also return true:
static bool All<T>(this IEnumerable<T> source, Func<T, bool> predicate);static bool Any<T>(this IEnumerable<T> ...