How to handle an “infinite” IEnumerable?

前端 未结 5 1831
醉梦人生
醉梦人生 2021-02-01 17:11

A trivial example of an \"infinite\" IEnumerable would be

IEnumerable Numbers() {
  int i=0;
  while(true) {
    yield return unchecked(i++);
  }
}
         


        
5条回答
  •  忘掉有多难
    2021-02-01 17:43

    If it wasn't lazy evaluation, your first example won't work as expected in the first place.

提交回复
热议问题