Created
March 23, 2011 14:16
-
-
Save forki/883148 to your computer and use it in GitHub Desktop.
Dealing with infinity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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