using System;
using static System.Console;
object obj = 7;
switch(obj) {
case string s:
WriteLine($"s = {s}");
break;
case int i when (i % 2 == 0):
WriteLine($"even i = {i}");
break;
case int i when (i % 2 == 1):
WriteLine($"odd i = {i}");
break;
case null:
throw new ArgumentNullException();
default:
WriteLine("unknown type");
break;
}
//prints: "odd i = 7"
| ✓ case 0: is the familiar constant pattern. ✓ case IEnumerable<int> childSequence: is a type pattern. ✓ case int n when n > 0: is a type pattern with an additional when condition. ✓ case null: is the null pattern. ✓ default: is the familiar default case. |