Code Inspection: Use method Any()
In a code snippet like this:
if (myEnumerable.Count() > 0)
ReSharper suggests replacing the
Count() > 0
part with the
extension method for two reasons. First,
is generally quicker as it does not iterate through the whole collection.
improves the readability of your code, indicating that the developer just wants to check if there
are any items in the collection and isn't concerned with the exact number of items.
Please note that if your type derives from
then you can use the
property which is definitely faster than both
Count(). Please make sure you don't confuse the
property with the