Skip to content
Justice Tech School

Practice: FizzBuzz

Combine a loop with a switch expression.

Example
for (int i = 1; i <= 15; i++)
{
    string s = (i % 3, i % 5) switch { (0, 0) => "FizzBuzz", (0, _) => "Fizz", (_, 0) => "Buzz", _ => i.ToString() };
    Console.Write(s + " ");
}

Exercise

Tuple pattern.

(a, b)  { }

Quiz Test

What does (0, _) match?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.