Skip to content

Instantly share code, notes, and snippets.

@neildanson
Forked from anonymous/FizzBuzzInCSharp7.cs
Last active December 4, 2017 10:12
Show Gist options
  • Save neildanson/75f1337b5664d6ab64f9357c6a74cd25 to your computer and use it in GitHub Desktop.
Save neildanson/75f1337b5664d6ab64f9357c6a74cd25 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