A trivial example of an \"infinite\" IEnumerable would be
IEnumerable Numbers() {
int i=0;
while(true) {
yield return unchecked(i++);
}
}
>
You would have to avoid any greedy functions that attempt to read to end. This would include Enumerable
extensions like: Count
, ToArray
/ToList
, and aggregates Avg
/Min
/Max
, etc.
There's nothing wrong with infinite lazy lists, but you must make conscious decisions about how to handle them.
Use Take
to limit the impact of an endless loop by setting an upper bound even if you don't need them all.