Should Count() of an IEnumerable be avoided?
问题 In general, I am using a List and then returning them as IEnumerable when I no longer need to update them. However, I ran into an issue where I actually need to enumerate through them but first need to know the count. Will IEnumerable enumerate every item and find the count (O(N)), or will it rely on List 's Count property (O(1))? Also, what if the IEnumerable is the result of a LINQ query? 回答1: Will IEnumerable enumerate every item and find the count (O(N)), or will it rely on List's Count