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.

Testing enum values

Testing enum values

- Once you've got some enumerated values, you're going to need to be able to test them. You're going to want to check whether days available, for example includes, Monday. So one way to do that is we can look at, let's say available Monday equals, and then we're going to use the D days available. That's our variable that holds that type. And because we're using the flags, we can choose Hasflag, Monday. Now we could do something like this, where we write out available Mondays, and then we'll put the variable in there. Then that is going to allow us to check, does it have that particular flag? So run that, available Mondays, true. That works great, if we have a flag. Another way we can compare these is using Bitwise operators. So let's say available Saturdays, and now we'll go in and we'll say, we've got D days available. We're going to Bitwise and that with shift days, Saturday, and then we'll check, does that equal shift days, Saturday. So that's how we'll get that value. And then…

Contents