Skip to content

Instantly share code, notes, and snippets.

@Keboo
Created Jan 26, 2018
Embed
What would you like to do?
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