myList.Count is the method in the list object, it just returns the value of the field, so very quickly. Since this is a small method, it will most likely be embedded by the compiler (or runtime), then they may allow other optimizations to be executed by the compiler.
myList.Count () calls the extension method (introduced by LINQ), which iterates over all the elements in IEnumerabl, so it should be much slower.
However (in Microsoft's implementation), the Count extension method has a βspecial caseβ for lists that allows it to use the Count count property, which means that the Count () method is only slightly slower than the Count property.
It is unlikely that you can tell the difference in speed in most applications.
So, if you know that you are dealing with a list, use the Count property, otherwise, if you have an "unknown" IEnumerabl, use the Count () method and let it optimize for you.
Ian Ringrose Nov 04 '10 at 3:22 a.m. 2010-11-04 15:22
source share