Getting the string representing the enum value

Victor Nakoryakov nail-mail at mail.ru
Sun Apr 2 03:22:49 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
> 
> 
>     void someFunc( X e )
>     {
>        toString(e);
>        e.string;
>        e.value;
>        //or something like that ..
>     }
> 
> Is there any such thing in D?
> 
Hello,

AFAIK, there is now way to do what you want directly. Simplest solution 
is to create helper map that would have X as a key and char[] as a value 
and then to define function toString(X x) the would return string 
representation.


-- 
Victor (aka nail) Nakoryakov
nail-mail<at>mail<dot>ru

Krasnoznamensk, Moscow, Russia



More information about the Digitalmars-d-learn mailing list