Jeremy Banks Jeremy Banks - 1 year ago 80
C# Question

How can I enumerate an infinite sequence of integers in C# 4.0?

Is there a function in C# that returns an

of the infinite sequence of integers
[0, 1, 2, 3, 4, 5 ...]

I'm currently doing

Enumerable.Range (0, 1000000000).Select (x => x * x).TakeWhile (x => (x <= limit))

to enumerate all squares up to
. I realize that this is effective, but if there's a built-in function that just counts up from
, I would prefer to use it.

Answer Source

This occurred to me, and is suitable for what I was doing:

Enumerable.Range (0, int.MaxValue)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download