Skip to content

Instantly share code, notes, and snippets.

@JayBazuzi
Created January 2, 2014 22:58
Show Gist options
  • Save JayBazuzi/8228748 to your computer and use it in GitHub Desktop.
Save JayBazuzi/8228748 to your computer and use it in GitHub Desktop.
Using a delegate instead of a single-method interface
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