|Thanks ! Really appreciate the details on the behavior of count/any in .NET history.
The timing study you cited is very interesting, but, my concern here is with IEnumerables that have not yet been iterated over.
i have seen an example of a generic class that inherits from IEnumerable<t>, overrides 'MoveNext, and sets a boolean property initialized to 'false to 'true, the first time 'MoveNext is called. i regret to say i can't find that code now ... which is driving me nuts.
If i understood what i have read recently, 'Any() will call 'MoveNext at least once, but, on return the Enumerable's 'current property will be #0. Interesting the source for 'Any shows it tries to convert the input to an IList: if that succeeds, it returns the IList .Count property.
i should make the context more specific here:
1) at runtime you have a collection, say: a List<int>
2. function chaining: you run that List through a series of Func methods each of which returns an IEnumerable<int>. assume you have good reasons for writing separate Funcs
2a) one case is cumulative: you collect the outcome of each Func, and concatenate that with some external IEnumerable variable you've defined/initialized. in this case a no-values result may not make a difference since such a rsult dioes not throw an error if concatenated.
2b) another case: you are filtering the source data, selecting the next items from the results of calling the previous Func. A series of "sieves" if you will.
3) consider the case where you want to do something when any of the series of Func calls returns an IEnumerable with no elements ... assume you have a method/Action defined that can be invoked by any of the series of Funcs in this "no result" case.
4) now consider the final IEnumerable result of the series of Funcs, assuming they were all invoked, and returned some values.
a) the benefits of using 'Any after each Func call seem obvious ... but ...
b) in the context of iterating the final IEnumerable result:
1) would converting the result of each Func call to a List or Array, have any benefits ?
or, any downside ?
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch