In the world of LINQ, predicate operators express Boolean-valued truths about sequences and their elements. Operators such as Any and 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

All and 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> ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.