Properties are expected to perform similarly to fields, even though they are really functions. What can be said about the expected performance of an arbitrary IEnumerable?
Is it fair to borrow the concept from properties and say that an IEnumerable should perform about the same as iterating an array or List<T>?
Or, is it okay for just about anything happen with each iteration: database access, web service call, time-consuming computation, etc.
Speaking from experience you can’t really infer anything about the performance of an arbitrary
IEnumerable. For example, it might be anIQueryablein disguise, hitting the database every time it is enumerated. Or it might be the result ofFile.EnumerateLines.Sometimes it is important that the enumerable only be enumerated once.
This is in contrast to a property. If a property was to hit the database or read I file I’d consider this to be a code smell. For an
IEnumerableit is just normal.