Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System;
namespace CSharp7PatternMatching
{
// Built for World of Zero: https://youtu.be/PQucU3VFiBA
class Program
{
static void Main(string[] args)
{
for (int i = 1; i < 100; ++i)
{
switch ((x: i % 3 == 0, y: i % 5 == 0))
{
case var fizzBuzz when fizzBuzz.x == true && fizzBuzz.y == true:
Console.WriteLine("Fizz Buzz");
break;
case var fizz when fizz.x == true && fizz.y == false:
Console.WriteLine("Fizz");
break;
case var buzz when buzz.x == false && buzz.y == true:
Console.WriteLine("Buzz");
break;
case var result when result.x == false && result.y == false:
Console.WriteLine($"{i}");
break;
}
}
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment