LINQ Any Operator - Test if any element of a sequence satisfies a condition

By Indranil Chatterjee

The LINQ Any operator allows to test if any element of a sequence satisfies a condition.

The following code sample demonstrates how:

int[] numbers = {3,5,6,9};
bool anyEven = numbers.Any(n => n % 2 == 0); // this returns true for the given array but false for {3,5,7,9}

LINQ Any Operator - Test if any element of a sequence satisfies a condition  (450 Views)