concept switch statement in category c#

This is an excerpt from Manning's book C# in Depth, Fourth Edition.
Using the tools available, you can decompile listing 6.1 into something like listing 6.2. Many of the names that the C# compiler generates aren’t valid C#; I’ve rewritten them as valid identifiers for the sake of getting runnable code. In other cases, I’ve renamed the identifiers to make the code more readable. Later, I’ve taken a few liberties with how the cases and labels for the state machine are ordered; it’s absolutely logically equivalent to the generated code, but much easier to read. In other places, I’ve used a switch statement even with only two cases, where the compiler might effectively use if/else. In these places, the switch statement represents the more general case that can work when there are multiple points to jump to, but the compiler can generate simpler code for simpler situations.
That’s ugly. It’s repetitive and long-winded; the same pattern of “check whether the shape is a particular type, and then use that type’s properties” occurs three times. Urgh. Importantly, even though there are multiple if statements here, the body of each of them returns a value, so you’re always picking only one of them to execute. The following listing shows how the same code can be written in C# 7 using patterns in a switch statement.
Listing 12.11. Computing a perimeter with patterns
static double Perimeter(Shape shape) { switch (shape) { case null: #1 throw new ArgumentNullException(nameof(shape)); #1 case Rectangle rect: #2 return 2 * (rect.Height + rect.Width); #2 case Circle circle: #2 return 2 * PI * circle.Radius; #2 case Triangle tri: #2 return tri.SideA + tri.SideB + tri.SideC; #2 default: #3 throw new ArgumentException(...); #3 } }This is quite a departure from the switch statement from previous versions of C#, in which case labels were all just constant values. Here you’re sometimes interested in just value matching (for the null case) and sometimes interested in the type of the value (the rectangle, circle, and triangle cases). When you match by type, that match also introduces a new variable of that type that you use to calculate the perimeter.
You’ve already seen an example of patterns in switch statements in section 12.3, where you used a constant pattern to match null and type patterns to match different kinds of shapes. In addition to simply putting a pattern in the case label, there’s one new piece of syntax to introduce.