Forked from simpleprogrammer-shared/lambda-extensible-fizzbuzz2-with-linq-1.cs
Created
June 21, 2019 16:08
-
-
Save dterracino/a9e788f398bf61e339ae42f37dc01a9c to your computer and use it in GitHub Desktop.
Lambda Extensible FizzBuzz 2.0 With LINQ
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
public static void FizzBuzz() | |
{ | |
Dictionary<Func<int, bool>, Func<int, string>> rules = new Dictionary<Func<int, bool>, Func<int, string>>(); | |
rules.Add(x => x % 3 == 0, x => "fizz"); | |
rules.Add(x => x % 5 == 0, x => "buzz"); | |
rules.Add(x => x % 5 != 0 && x % 3 != 0, x => x.ToString()); | |
rules.Add(x => true, x => "\n"); | |
var output = from n in Enumerable.Range(1, 100) | |
from f in rules | |
where f.Key(n) | |
select f.Value(n); | |
output.ToList().ForEach(x => Console.Write(x)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment