Udostępnij za pośrednictwem


How to: Specify Underlying Types of Enums

By default, the underlying type of an enumeration is int. However, you can specify the type to be signed or unsigned forms of int, short, long, __int32, or __int64. You can also use char.

Example

Code

// mcppv2_enum_3.cpp
// compile with: /clr
public enum class day_char : char {sun, mon, tue, wed, thu, fri, sat};

int main() {
   // fully qualified names, enumerator not injected into scope
   day_char d = day_char::sun, e = day_char::mon;
   System::Console::WriteLine(d);
   char f = (char)d;
   System::Console::WriteLine(f);
   f = (char)e;
   System::Console::WriteLine(f);
   e = day_char::tue;
   f = (char)e;
   System::Console::WriteLine(f);
}

Output

sun
0
1
2

See Also

Reference

enum class