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

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…

Contents