Equivalent of ToString() on an enum type in C++/CLI
c++-cli
Solution
Whilst the other answers are not incorrect, I found myself with the same problem. In my case, I had declared a standard C++ enum and forgot to use the CLI syntax (even though I had it been exposed in public properties without compiler warnings!).
The proper syntax for a C++/CLI enum is (Note the word 'class'):
public enum class SomeEnum {
Value1,
Value2
}
NB: You can also use 'struct' rather than 'class'.
You will also need to go back through your code and change any assignments (the compiler will happily show you the errors however) from this:
SomeEnum value = Value1;
to this:
SomeEnum value = SomeEnum::Value1;
You will now find that 'ToString()' works as you'd expect it to.
Problem
In C# you can declare an enum and once you have set its value call ToString on the variable and get a string representation of the value of the enum. How do you do this in C++/CLI using a managed enum?