While moving my blog content from site to site my post on Fizz-buzz caught my eye again. I thought I would post another implementation that was even more complex (read don’t use in your interview)

This one uses the iterator pattern and the null coalescing operator for added complexity.

void Main()
{
    Console.WriteLine(string.Join(", ", FizzBuzz().Take(100).ToArray()));
}

string[,] fbLogic = new string[2, 2]
{
    {"Fizz-Buzz", "Fizz" },
    {"Buzz", null }
};

IEnumerable FizzBuzz()
{
    for (int i = 1; true; ++i)
    {
        yield return fbLogic[i % 3 == 0 ? 0 : 1, i % 5 == 0 ? 0 : 1] ?? i.ToString();
    }
}