Getting the string representing the enum value

Jason Mills jmills at cs.mun.ca
Sun Apr 2 07:25:19 PDT 2006


Hasan Aljudy wrote:
> say I have an enum
> 
>     enum X
>     {
>      A,
>      B,
>      C
>     }
> 
> and I have
> 
>     void someFunc( X e )
>     {
>      //.. some code
>     }
> 
> I want to print the value of 'e' but I don't want to get a number!! I 
> want to get a string that represents it. i.e. A or B or C
> 
> Is there any such thing in D?
> 

Sadly, no. I once suggested that enums be a little smarter, more like 
.NET enums or, even better in my opinion, Java 5 enums. Being able to 
obtain a string representation from an enum value, parsing an enum value 
from a string, and (in Java versions) attach functionality or custom 
strings to enum values, is very powerful.

If I remember correctly, the idea was rejected out right. Maybe there 
are performance issues?

Jason



More information about the Digitalmars-d-learn mailing list