Created
January 26, 2018 23:28
-
-
Save Keboo/72b436607426662ba383d258cb6db0df to your computer and use it in GitHub Desktop.
Optional FizzBuzz
This file contains 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 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