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.
Solution: Enum Flags - C# Tutorial
From the course: C# Essential Training 1: Types and Control Flow
Solution: Enum Flags
- [Instructor] We start with our days of the week enum, which has INT as a base type. And the test then is going to check whether or not, if we take two days, Monday and Friday, and combine them together, using the bitwise operator there, we get the result. So if we just test by default, you'll see our code returned Friday. It only returned one of those values. So the key thing we need to add is the Flags attribute, but that didn't quite fix it. Though the Flags is one piece of the answer, we do need to say, I can represent multiple values here, but the other thing we want to do is give these particular enums values. So I want to make them use values that allow me to combine them. So you'll notice I'm not just incrementing by one here, I'm essentially doubling them, and that allows me to combine them. So I know, for example, that if I take something like Sunday and Monday and add them together, that gives me a value of…
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)
-
-