tags:

views:

37

answers:

1

Sort of a Linq beginners question, but is there a simple built-in way to optimize this:

bool containsItemWithValue42 = items.Where(i => i.Value == 42).Count() > 0;

I would like Linq to stop iterating as soon as it found a match.

+5  A: 

The Any method does exactly that:

bool containsItemWithValue42 = items.Any(i => i.Value == 42);
Fredrik Mörk
Of course! #smackonforehead# Thanks!
bitbonk