Enum to string array

ylixir ylixir at gmail.com
Wed Oct 1 05:47:10 PDT 2008


Spacen Jasset wrote:
> 
> 
> enum Symbols {
>         CYCLIC_FORWARD, CYCLIC_BACKWARD, CYCLIC_LEFT, etc
> };
> 
> How could I map this into an array? (or vice-versa) must I use a switch 
> statement, or an enum -> string mapping array?

maybe an associative array is what you are looking for?

something like:

char[][Symbols] theArray;

theArray[Symbols.CYCLIC_FORWARD] = "Cycle Forward";
theArray[Symbols.CYCLIC_BACKWARD] = "Cycle Backwards";

writefln(theArray[Symbols.CYCLIC_FORWARD]); //prints "Cycle Forward"
writefln(theArray[Symbols.CYCLIC_BACKWARDS]); //prints "Cycle Backwards"


More information about the Digitalmars-d-learn mailing list