Represent Enum values as String

I have this Enum

Public Enum HotkeyModifiers As Short
    SHIFT = 1
    CONTROL = 2
    ALT = 4
    NONE = 0
End Enum

So 6 is equals to ALT+CONTROL, so when I do this:

 MsgBox((HotkeyModifiers.CONTROL Or HotkeyModifiers.ALT).ToString)
MsgBox([Enum].Parse(GetType(HotkeyModifiers), 6).ToString)

I expect to get this output as String:

CONTROL, ALT

Because If I try to do the same with a framework enum like for example the Keys enum:

MsgBox((Keys.Alt Or Keys.ControlKey).ToString)

I get this string:

ControlKey, Alt

Then what I'm missing to do in my Enumeration?

Jon Skeet
people
quotationmark

You need to decorate your enum with FlagsAttribute.

<Flags>
Public Enum HotkeyModifiers As Short
    SHIFT = 1
    CONTROL = 2
    ALT = 4
    NONE = 0
End Enum

That affects the behaviour of both ToString and parsing.

people

See more on this question at Stackoverflow