O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Predicates

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required