5 Mar 2010

My FizzBuzz (@kriegaffe @chris_bc)

            for (int i = 1; i <= 100; i++)
            {
                String s;
                if (i % 3 == 0)
                    s = "Fizz";
                if (i % 5 == 0)
                    s += "Buzz";
                if (s.Length == 0)
                    s = i.ToString();

                Console.WriteLine(s);
            }

You can argue about whether using a string is more or less efficient than doing a second i%3 and i%5, but it's certainly more elegant.