LINQ Any Operator

By Peter Bromberg

The Any operator checks whether any element of a sequence satisfies a condition. The Any operator enumerates the source sequence and returns true if any element satisfies the test given by the predicate. If no predicate function is specified, the Any operator simply returns true if the source sequence contains any elements.

int[] twos = { 2, 4, 6, 8, 10 };

bool containsMultipleOfThree = twos.Any(i => i % 3 == 0);

or something like this:  bool b = products.Any(p => p.UnitPrice >= 100 && p.UnitsInStock == 0);





LINQ Any Operator  (887 Views)