Overview

A quantifying operation return Boolean for whether some or all of the elements in a set satisfy a condition.

methods

MethodDescriptionQuery expression
AllBool whether all elements in a collection satisfy a conditionN/A
AnyBool whether any elements in a collection satisfy a conditionN/A
ContainsBool whether a collection contains a specified elementN/A

All

In this example, find students that scored above 70 on all exams:

IEnumerable<string> names = from student in students
                            where student.Scores.All(score => score > 70)
                            select $"{student.FirstName} {student.LastName}: {string.Join(", ", student.Scores.Select(s => s.ToString()))}";

Any

In this example, find students that scored above 95 on any exam:

Enumerable<string> names = from student in students
                            where student.Scores.Any(score => score > 95)
                            select $"{student.FirstName} {student.LastName}: {student.Scores.Max()}";

Contains

In this example, find students that scored exactly 95 on an exam:

IEnumerable<string> names = from student in students
                            where student.Scores.Contains(95)
                            select $"{student.FirstName} {student.LastName}: {string.Join(", ", student.Scores.Select(s => s.ToString()))}";