Created
January 2, 2014 22:58
-
-
Save JayBazuzi/8228748 to your computer and use it in GitHub Desktop.
Using a delegate instead of a single-method interface
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 string FizzBuzz(int i) | |
{ | |
Func<int, string> number = x => x.ToString(); | |
Func<int, string> fizz = x => "Fizz"; | |
Func<int, string> buzz = x => "Buzz"; | |
Func<int, string> fizzBuzz = x => "FizzBuzz"; | |
return new[] | |
{ | |
fizzBuzz, //15 | |
number, // 1 | |
number, // 2 | |
fizz, // 3 | |
number, // 4 | |
buzz, // 5 | |
fizz, // 6 | |
number, // 7 | |
number, // 8 | |
fizz, // 9 | |
buzz, //10 | |
number, //11 | |
fizz, //12 | |
number, //13 | |
number, //14 | |
}[i % 15](i); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment