quot;This is a Person. Name is: {name}"); } ``` <br> Relational pattern и Logical pattern ```csharp Person person = GetPerson(); if (person is { Name: "John" or "Jane", Health: > 50 }) { Console.WriteLine("This is either John or Jane with more than 50 health points"); } ``` <br> When pattern (без Var Pattern не обойтись) ```csharp Person person = GetPerson(); if (person is { Name: "John" } and { Health: var health } when health > 50) { Console.WriteLine(quot;This is John with {health} health points"); } ``` <br> Negated pattern ```csharp Person person = GetPerson(); if (person is { Name: not "John" }) { Console.WriteLine("This person is not John"); } ``` <br> Использование вместе с as ```csharp object obj = new Person("John", "Doe", 35); var person = obj as Person { Age: var age } switch { Person { Age: >= 18 } => quot;Person is older than 18, actual age: {age}", _ => "Person is under 18 or not a person" }; ``` <br> <br> Прочие примеры ```csharp public static string GetWeatherDescription(Weather weather) => weather switch { { Temperature: (< 0), Sky: Clear } => "Холодно и ясно", { Temperature: (> 30), Sky: Cloudy } => "Жарко и облачно", { Temperature: (> 30) and (< 45), Sky: Sunny } => "Тепло и солнечно", { Rainfall: (> 0) and (< 10), Sky: Rainy } => "Легкий дождь", _ => "Неизвестная погода" }; ```