Enum to string array

Spacen Jasset spacenjasset at yahoo.co.uk
Wed Oct 1 09:03:26 PDT 2008

ylixir wrote:
> Spacen Jasset wrote:
>> enum Symbols {
>> };
>> 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"

Yes indeed. But I really would like it to map the other way, also it's a 
bit akward as you have to add an enum entry and a AA aray entry. But 
it's defiantly a possible solution. At the moment I have parallel 
arrays, which is also a bit risky.

More information about the Digitalmars-d-learn mailing list