Skip to content

Instantly share code, notes, and snippets.

@Keboo
Created January 26, 2018 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Keboo/72b436607426662ba383d258cb6db0df to your computer and use it in GitHub Desktop.
Save Keboo/72b436607426662ba383d258cb6db0df to your computer and use it in GitHub Desktop.
Optional FizzBuzz
public static void Main()
{
var obj = new Printer();
IFizz fizz = obj;
IBuzz buzz = obj;
IFizzBuzz fizzBuzz = obj;
for (int i = 0; i < 100; i++)
{
if (i % 15 == 0)
fizzBuzz.Print();
else if (i % 3 == 0)
buzz.Print();
else if (i % 5 == 0)
fizz.Print();
else
obj.Print(i.ToString());
}
}
public interface IBuzz
{
void Print(string value = "Buzz");
}
public interface IFizz
{
void Print(string value = "Fizz");
}
public interface IFizzBuzz
{
void Print(string value = "FizzBuzz");
}
public class Printer : IFizz, IBuzz, IFizzBuzz
{
public void Print(string value)
{
Console.Write(value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment