Why does Enumerable.All return true for an empty sequence? [duplicate]

It’s certainly not a bug. It’s behaving exactly as documented:

true if every element of the source sequence passes the test in the specified predicate, or if the sequence is empty; otherwise, false.

Now you can argue about whether or not it should work that way (it seems fine to me; every element of the sequence conforms to the predicate) but the very first thing to check before you ask whether something is a bug, is the documentation. (It’s the first thing to check as soon as a method behaves in a way other than what you expected.)

Leave a Comment