I have an enum (flag)
[Flags]
public enum DisplayMode
{
None,
Dim,
Inverted,
Parse,
Italics,
Bold
}
I want to assign two of the flags to a variable, like this:
var displayFlags = DisplayMode.Parse | DisplayMode.Inverted;
However, when I debug and hover over this variable immediately after it is assigned, it says displayFlags is DisplayMode.Dim | DisplayMode.Inverted.
What am I missing/not understanding?
You’ve missed assigning the flags sensible values, e.g.:
That way each value has a separate bit in the numeric representation.
If you don’t trust your ability to double values, you can use bit shifting:
From the documentation from
FlagsAttribute: