digitalmars.D.learn - array of constants?
- Lloyd Dupont (11/11) Jun 02 2011 I'm trying to define an array of constant like:
- Etherous (9/9) Jun 02 2011 You need to set it in a static constructor
- Lloyd Dupont (11/11) Jun 03 2011 thanks!
I'm trying to define an array of constant like: === immutable string[int] MyDict = [ 1: "monday", 2: "tuesday", ]; ==== And I keep having compiler error: Error 1 Error: non-constant expression [1:"monday",2:"tuesday"] C:\Dev\DTest\DTest1\Dexperiment\LCIDs.d 9 what can I do? how do I do that?
Jun 02 2011
You need to set it in a static constructor immutable string[int] MyDict; static this () { MyDict = cast(string[int]) [ 1: "monday", 2: "tuesday" ]; }
Jun 02 2011
thanks! "Etherous" wrote in message news:is8dbh$n22$1 digitalmars.com... You need to set it in a static constructor immutable string[int] MyDict; static this () { MyDict = cast(string[int]) [ 1: "monday", 2: "tuesday" ]; }
Jun 03 2011