In most code that you find that uses lists you will find something like this:
if(products.Count() > 0)
{
// Do stuff
}
Personally, I’ve seen this literally thousands of times. While this works and gets the job done, there is one issue with this method. It enumerates the entire enumerable collection. What if you have 10,000 items in your collection? What if that collection has a bunch of other nested LINQ queries that must be executed prior to the actual count can be evaluated?
A simpler way to identify if the sequence contains any...
Read more...