Created
March 2, 2016 19:06
-
-
Save Mohammed-El-Nabulsi/57a564c11d91452d17fb to your computer and use it in GitHub Desktop.
FizzBuzz... Let's jump the Hype-Train.
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
// Thanks to Igor Fischer for continuous support! | |
static class Extensions | |
{ | |
public static IEnumerable<T> ForEach<T>(this IEnumerable<T> sequence, Action<T> action) | |
{ | |
foreach (T item in sequence) action(item); | |
return sequence; | |
} | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var range = Enumerable.Range(1, 15); | |
var fizzBuzz = new Func<int, string>(i => | |
i % 15 == 0 ? "FizzBuzz" | |
: i % 3 == 0 ? "Fizz" | |
: i % 5 == 0 ? "Buzz" : i.ToString() | |
); | |
range.Select(fizzBuzz).ForEach(Console.WriteLine); | |
Console.ReadKey(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment