Export (0) Print
Expand All

How to: Convert Between Managed and Standard Enumerations

There is no standard conversion between an enum and an integral type; a cast is required.

Code

// mcppv2_enum_4.cpp
// compile with: /clr
enum class day {sun, mon, tue, wed, thu, fri, sat};
enum {sun, mon, tue, wed, thu, fri, sat} day2; // unnamed std enum

int main() {
   day a = day::sun;
   day2 = sun;
   if ((int)a == day2)
   // or...
   // if (a == (day)day2)
      System::Console::WriteLine("a and day2 are the same");
   else
      System::Console::WriteLine("a and day2 are not the same");
}

Output

a and day2 are the same

Community Additions

ADD
Show:
© 2014 Microsoft