What does the [Flags] Enum Attribute mean in C#?

The [Flags] attribute should be used whenever the enumerable represents a collection of possible values, rather than a single value. Such collections are often used with bitwise operators, for example: var allowedColors = MyColor.Red | MyColor.Green | MyColor.Blue; Note that the [Flags] attribute doesn’t enable this by itself – all it does is allow a … Read more

Get int value from enum in C#

Just cast the enum, e.g. int something = (int) Question.Role; The above will work for the vast majority of enums you see in the wild, as the default underlying type for an enum is int. However, as cecilphillip points out, enums can have different underlying types. If an enum is declared as a uint, long, … Read more

Referring to c++ enums [closed]

In all versions of C++, the second version (Foo::States::BAR) using scope syntax is the more conventional and will be less surprising for future maintainers of your code. Since the value is a constant, there is no need for an instance of the class, so this is similar to how static methods are most often called … Read more

How to declare enums in C#

Enum values should be from the same type. So your second example almost works. If you are using flags, you should give all the values an name or index, not just one: enum cardValue { Val2 = “2”, Val3 = “3”, Val4 = “4”, ValA = “A” }; Also, variable names, class names, enum values, … Read more