Trying to get the underlying Integer value for my enum returned as a String.
Tried
return ((int) MyEnumValue).ToString;
But fails with
Error 1 Cannot convert method group 'ToString' to non-delegate type 'string'. Did you intend to invoke the method?
We can convert an enum to string by calling the ToString() method of an Enum.
ToString(String)Converts the value of this instance to its equivalent string representation using the specified format.
The stringify() macro method is used to convert an enum into a string. Variable dereferencing and macro replacements are not necessary with this method. The important thing is that, only the text included in parenthesis may be converted using the stringify() method. Let's demonstrate the code implementation.
The toString() method of Enum class returns the name of this enum constant, as the declaration contains. The toString() method can be overridden, although it's not essential.
The less parentheses option is:
return MyEnumValue.ToString("d");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With