2 ms·
Definitely. Should have left that first line out, as it wasn't what I was trying to argue. The rest of my point still stands. Edit: I see you've appended to yo
by upthedale 14y ago
Definitely. Should have left that first line out, as it wasn't what I was trying to argue. The rest of my point still stands.
Edit: I see you've appended to your comment. The problem is you could always have lazily-evaluated IEnumerables by implementing an IEnumerator. It was just a pain in the arse until C#2 brought us generator support through the yield keyword. This was long before Linq came along.
Edit2:
> There were years and years where IEnumerable simply defined an object that could be enumerated...
Which is my point exactly. And nothing has changed with IEnumerable (generics excluded). It certainly doesn't say that all the objects are already held in-memory (as enforcing ToList would do). By returning an IEnumerable, you're just saying here's an object that can produce you a sequence of results. In a public API, it should be documented (at least some vague allusion to) whether this will be produced by trivially pulling them out of an in-memory list, or whether something a bit more clever is going on, as there'll certainly be occasions where streaming the results through a generator is more desirable than holding them all in memory.