July 2017
Beginner
466 pages
9h 37m
English
The new switch case statement pattern enhances the case blocks by comparing the value, not just by constants, but also by an expression. In C# 7.0, you can generalize the switch statement in the following manner:
Let's look at the following example, where we have the base Person reference passed to the switch statement:
public static void Validate(Person person) { switch (person) { case Employee e: Console.WriteLine($"{e.Firstname} is an Employee"); break; case Customer c when (c.IsPremium): Console.WriteLine($"{c.Firstname} ...Read now
Unlock full access