This documentation is archived and is not being maintained.

12 __value Enums

Visual Studio .NET 2003


A __value enum is similar to an ordinary C++ enumerated type except for the following:

  • A __value enum can specify an underlying type.
  • By default pointer-to rules, a pointer-to a __value enum type is a __gc pointer.
  • A __value enum name can conflict with another name in the same scope without error. See the first example in Section 12.1.
  • A __value enum has metadata emitted that describes its type and all of its members.
  • A __value enum can be declared in a __gc interface.

Any enum declared with the __value class key modifier is a __value enum.


__value enum Color {red, green, blue}; 

The compiler does not use context to determine whether an enum is managed. The following constraint prevents possible confusion.


  • An enum declared within a __gc class, __gc struct, __value class, or __value struct shall specify the __value class-key modifier.


    // __value_enums.cpp
    // compile with: /clr
    #using <mscorlib.dll>
    __gc struct G {
       enum Color {red, green, blue};   // C3277
       __value enum Weekend { Sunday, Saturday };   // OK