if (something.Count() == 0) { … } construct

Do not use such a construct:

if (something.Count() == 0) 
{ 
   ... 
}

We are not interested in the real count of items in something.
Only the presence of items is the point of our interest.
So write instead of above this:

if (something.Any())
{
   ...
}

This will stop at the first item which will result in better performance in
cases where something contains a lot of items.

2 thoughts on “if (something.Count() == 0) { … } construct

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.