Skip to content

Instantly share code, notes, and snippets.

@mwolicki
Forked from neildanson/FizzBuzzInCSharp7.cs
Created December 4, 2017 10:12
Show Gist options
  • Save mwolicki/12d516fee5c5ea9cd28b5e9d4fb957e4 to your computer and use it in GitHub Desktop.
Save mwolicki/12d516fee5c5ea9cd28b5e9d4fb957e4 to your computer and use it in GitHub Desktop.
using System;
namespace FizzBuzz
{
class Program
{
static void Main(string[] args)
{
for(int i=1;i<=100;i++) {
switch (new { mod3 = i % 3, mod5 = i % 5 }) {
case var t when t.mod3 == 0 && t.mod5 == 0:
Console.WriteLine("FizzBuzz");
break;
case var t when t.mod3 == 0:
Console.WriteLine("Fizz");
break;
case var t when t.mod5 == 0:
Console.WriteLine("Buzz");
break;
default:
Console.WriteLine(i);
break;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment