Associative Array, key and value as type of string or char[]

Ali Çehreli acehreli at yahoo.com
Sat Feb 2 21:09:52 PST 2013


On 02/02/2013 08:00 AM, timewulf wrote:

 > After searching for the differences to my code, I found my fault:

It is not your fault. :)

 > Now I've just to look, how to declare this array in the way of public
 > constants.

You need 'static this()':

import std.stdio;

string[string] ch_Description;

static this()
{
     ch_Description = [ "kill" : "kills a process",
                        "pause" : "pauses a process" ];
}

void main() {
     // ...
}

You can even make the AA immutable if it never changes:

immutable string[string] ch_Description;

Ali



More information about the Digitalmars-d-learn mailing list