LINQ Contains Operator

By Peter Bromberg

The Contains operator checks whether a sequence contains a given element.

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

// true
bool areAllevenNumbers = twos.All(i => i % 2 == 0);

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

// false
bool hasSeven = twos.Contains(7);

LINQ Contains Operator  (687 Views)