From the course: Ten Tips for the C# Developer
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Better switch statements with pattern matching - C# Tutorial
From the course: Ten Tips for the C# Developer
Better switch statements with pattern matching
- [Instructor] The switch statement has been part of the C# specifications since the beginning. It's been around for decades. It's always had this brittle syntax, at least when you compare it to other programming languages like Visual Basic. There's just less flexibility in what you could do in the C# switch. But that is changing. Microsoft has made some edits and updates in the last couple of versions of C# and I thought we would look at something called pattern matching in this video. We'll start by looking at the old style of a case and a switch. So here, I am switching on an integer value called number. That was one of the restrictions we saw in the past, is that there was only a few types you could switch on, some numeric types like integers and longs and some strings. That's now been improved and I'll show you that later in this video. And then when it came to writing your case labels, you tended to…
Contents
-
-
-
Avoid race condition with TryGetValue method1m 46s
-
Better switch statements with pattern matching6m 42s
-
Readable literals with the underscore4m 8s
-
Extract items from sequence with indices9m 8s
-
Discard feature5m 3s
-
Be more functional with the conditional operator2m 42s
-
Create a thread-safe immutable type5m 13s
-
Use the ImmutableList collection4m 14s
-
Show custom debugger information4m 49s
-
Work with nested collections and SelectMany2m 45s
-
-