CSharp examples for Language Basics:switch
Solve Fizz Buzz problem using case when statement
using System;// w w w. j a v a 2 s . c om using System.Collections.Generic; using System.Text; class FizzBuzz { static void Main() { for (int i = 1; i < 50; i++) { PrintFizzBuzz(i); } } static void PrintFizzBuzz(int n) { switch (n) { case var _ when n % 3 == 0: Console.Write("Fizz"); goto case 0; case 0: break; case var _ when n % 5 == 0: Console.Write("Buzz"); break; default: Console.WriteLine(n); break; } } }