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 - C# Tutorial
From the course: C# Essential Training 1: Types and Control Flow
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…
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)
Defining enums4m 39s
-
(Locked)
Enabling multiple enum values4m 3s
-
(Locked)
Testing enum values4m 13s
-
(Locked)
Understanding nullable types3m 24s
-
(Locked)
Using nullable types2m 14s
-
(Locked)
Working with null objects3m 25s
-
(Locked)
Understanding nullable reference types4m 23s
-
(Locked)
Working with nullable reference types4m 8s
-
(Locked)
Solution: Enum Flags1m 42s
-
(Locked)
-
-