linq Standard Query Operators Quantifier Operations

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

Quantifier operations return a Boolean value that indicates whether some or all of the elements in a sequence satisfy a condition.

All

Determines whether all the elements in a sequence satisfy a condition.

Method Syntax

// All

var numbers = new int[] { 1, 2, 3, 4, 5 };

bool areLessThan10 = numbers.All(n => n < 10);

// areLessThan10 = true

Query Syntax

// Not applicable.

Any

Determines whether any elements in a sequence satisfy a condition.

Method Syntax

// Any

var numbers = new int[] { 1, 2, 3, 4, 5 };

bool anyOneIsEven = numbers.Any(n => n % 2 == 0);

// anyOneIsEven = true

Query Syntax

// Not applicable.

Contains

Determines whether a sequence contains a specified element.

Method Syntax

// Contains

var numbers = new int[] { 1, 2, 3, 4, 5 };

bool appears = numbers.Contains(10);

// appears = false

Query Syntax

// Not applicable.


Got any linq Question?