Last active
August 29, 2015 14:02
-
-
Save smith-neil/8cd342a303b482b880aa to your computer and use it in GitHub Desktop.
One line Fizz Buzz.... but why?
This file contains hidden or 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
| Enumerable.Range(1, 100) | |
| .FirstOrDefault(m => | |
| { | |
| Console.WriteLine( | |
| m % 15 == 0 ? "FizzBuzz" : | |
| m % 5 == 0 ? "Buzz" : | |
| m % 3 == 0 ? "Fizz" : | |
| m.ToString() | |
| ); | |
| return false; | |
| } | |
| ); | |
| I use the FirstOrDefault hack so I can always return false and therefore move to the next item | |
| in the collection without ever copying the enumeration to a new list. | |
| Yes I know this is bad. Yes it was fun to write. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment