Linq does a lot of clever things such as returning the result of the Count-property using the Count
() method on a IList
.
Is there a good source that gives an overview of this optimizations?
It would be very interesting because as before I knew the above, I never used Count()
and thus often returned a List<T>
than only an IEnumerable<T>
because i knew that the caller will need need often the instance-count of the list.
But having in mind that Count() does not really count the instances contained in the IEnumerable<T>
but returns the result of the Count-property from the returned List and therefore not loosing performance occasioned me to change a lot of my returning types from a List to IEnumerable<T>
.