Skip to content

Instantly share code, notes, and snippets.

@forki
Created March 23, 2011 14:16
Show Gist options
  • Save forki/883148 to your computer and use it in GitHub Desktop.
Save forki/883148 to your computer and use it in GitHub Desktop.
Dealing with infinity
// you can do this even with BigInteger
static IEnumerable<long> AllNumbers()
{
var x = 0;
while (true)
yield return x++;
}
static IEnumerable<long> AllEvenNumbers()
{
return AllNumbers().Where(x => x % 2 == 0);
}
static void Main(string[] args)
{
foreach (var evenNumber in AllEvenNumbers().TakeWhile(x => x < 100))
{
Console.WriteLine(evenNumber);
}
Console.ReadKey();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment