# Craig PhillipsFizzBuzz - 3 different implementations.

Created by Craig Phillips
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72``` ```using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace FizzBuzz { class Program { static void Main(string[] args) { /* * Write a program that prints the numbers from 1 to 100. * But for multiples of three print "Fizz" instead of the number * and for the multiples of five print "Buzz". * For numbers which are multiples of both three and five print "FizzBuzz". */ // This is the "classic" solution to the FizzBuzz problem. for (int i = 1; i <= 100; i++) { if (i % 3 == 0 && i % 5 == 0) { Console.WriteLine("FizzBuzz"); } else if (i % 3 == 0) { Console.WriteLine("Fizz"); } else if (i % 5 == 0) { Console.WriteLine("Buzz"); } else { Console.WriteLine(i.ToString()); } } // Wait for the user to hit "Enter" after displaying the list above. Console.ReadLine(); // This is a "contemporary" solution to the FizzBuzz problem using LINQ. Enumerable.Range(1, 100).ToList().ForEach(n => Console.WriteLine((n % 3 == 0) ? (n % 5 == 0) ? "FizzBuzz" : "Fizz" : (n % 5 == 0) ? "Buzz" : n.ToString())); // Wait for the user to hit "Enter" after displaying the list above. Console.ReadLine(); // Extensible FizzBuzz! Dictionary, Func> rules = new Dictionary, Func>(); rules.Add(x => x % 3 == 0, x => "fizz"); rules.Add(x => x % 5 == 0, x => "buzz"); rules.Add(x => x % 5 != 0 && x % 3 != 0, x => x.ToString()); rules.Add(x => true, x => "\n"); var output = from n in Enumerable.Range(1, 100) from f in rules where f.Key(n) select f.Value(n); output.ToList().ForEach(x => Console.Write(x)); // Wait for the user to hit "Enter" after displaying the list above. Console.ReadLine(); // Exit from the application. Environment.Exit(0); } } } ```