From the course: C# Essential Training 1: Types and Control Flow
Unlock the full course today
Join today to access over 23,200 courses taught by industry experts.
Constant, relational, and logical patterns - C# Tutorial
From the course: C# Essential Training 1: Types and Control Flow
Constant, relational, and logical patterns
- [Instructor] Let's go back up to our switch statement here. And you can see as an example, we were using a constant pattern here, where we're using a constant value, in this case, chars, to do that. What if I want to use something that's more relational? So maybe I want to say it's greater than lowercase a or it's less than a lowercase z. You can see, I've got some little squigglies, some warnings and errors because I'm mixing and matching here the relational pattern with the constant pattern. We'll get that fixed shortly. What I really want is to mix these in a single statement and that's where a logical pattern can come in. So I can say if it's greater than, actually what I really want is greater than or equal to a, and I want it to be less than or equal to z. This is how you might think you would write it, but you actually want to use and in here. So it's a little different than our normal C# syntax. So we'll get rid of this line. And now we're saying, "Hey, if it's a lowercase…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
(Locked)
If and switch revisited5m 26s
-
(Locked)
Switch statement vs. switch expression4m 55s
-
(Locked)
Using the is expression5m 22s
-
(Locked)
Introduction to patterns3m 46s
-
(Locked)
Constant, relational, and logical patterns3m 17s
-
(Locked)
Property pattern4m 22s
-
(Locked)
Guard conditions3m 57s
-
(Locked)
Solution: Switch expression using patterns2m 16s
-
(Locked)
-