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

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…

Contents