Tip: IEnumerable.All() always returns true for empty sets

This handy tip might save you from being bitten by an odd edge case:

Assert.IsTrue(new object[]{}.All(x=> false));

This assertion will always pass on an empty set, no matter what the lambda expression.

I scratched my head and thought about it for a it, and agreed that I don’t see any better way the .NET team could have implemented this, from an API perspective.

Tuesday, 14 August 2012

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s