Skip to content

Instantly share code, notes, and snippets.

@Mohammed-El-Nabulsi
Created March 2, 2016 19:06
Show Gist options
  • Save Mohammed-El-Nabulsi/57a564c11d91452d17fb to your computer and use it in GitHub Desktop.
Save Mohammed-El-Nabulsi/57a564c11d91452d17fb to your computer and use it in GitHub Desktop.
FizzBuzz... Let's jump the Hype-Train.
// 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