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.
Enabling multiple enum values - C# Tutorial
From the course: C# Essential Training 1: Types and Control Flow
Enabling multiple enum values
- [Instructor] If we try to take our type an add by using a Bitwise operator like the or, let's say Thursday. What we'd like is for our days available when we represent it or say D days available here in our console right line to show Wednesday and Thursday. We're combining those two values. If we do this, we run it, you'll see we get 24, which is Thursday plus Wednesday. It is 16 plus 8, and that is the integer value, but that's not really what we want. Certainly we could store it in the database that way, that's why we numbered them this way. But we don't really want that. What we want to be able to do is treat them a little more like Bitwise operators with flags. So we can add an attribute called flags to our enum. And that essentially tells the compiler to treat it a little bit differently and that this particular enum can have multiple values in it. So simply by adding that flags attribute, if I run it now, we see we get Wednesday, Thursday. That's what we would expect in our…
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)
-
-