Skip to content

Instantly share code, notes, and snippets.

@buvinghausen
Last active March 9, 2026 15:29
Show Gist options
  • Select an option

  • Save buvinghausen/95f30490ed5adff510a02f108703d871 to your computer and use it in GitHub Desktop.

Select an option

Save buvinghausen/95f30490ed5adff510a02f108703d871 to your computer and use it in GitHub Desktop.
FizzBuzz using C# pattern matching, value tuples, and a switch expression
FizzBuzz(63).ForEach(Console.WriteLine);
return;
static List<string> FizzBuzz(int count) => [.. Enumerable
.Range(1, count)
.Select(i => (i % 3 == 0, i % 5 == 0) switch
{
(true, false) => "Fizz",
(false, true) => "Buzz",
(true, true) => "FizzBuzz",
_ => $"{i}"
})];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment