Working with a collection I have the two ways of getting the count of objects; Count
(the property) and Count()
(the method). Does anyone know what
If there is a Count
or Length
property, you should always prefer that to the Count()
method, which generally iterates the entire collection to count the number of elements within. Exceptions would be when the Count()
method is against a LINQ to SQL or LINQ to Entities source, for example, in which case it would perform a count query against the datasource. Even then, if there is a Count
property, you would want to prefer that, since it likely has less work to do.