The Any()
with the predicate can perform its task without an iterator (yield return
). Using a Where()
creates an iterator, which adds has a performance impact (albeit very small).
Thus, performance-wise (by a bit), you're better off using the form of Any()
that takes the predicate (x => x.Name == "bla"
). Which, personally, I find more readable as well...
On a side note, Where()
does not necessarily enumerate over all elements, it just creates an iterator that will travel over the elements as they are requested, thus the call to Any()
after the Where()
will drive the iteration, which will stop at the first item it finds that matches the condition.
So the performance difference is not that Where()
iterates over all the items (in linq-to-objects) because it really doesn't need to (unless, of course, it doesn't find one that satisfies it), it's that the Where()
clause has to set up an iterator to walk over the elements, whereas Any()
with a predicate does not.