Thread overview
array of constants?
Jun 02, 2011
Lloyd Dupont
Jun 02, 2011
Etherous
Jun 03, 2011
Lloyd Dupont
June 02, 2011
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? 

June 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"
  ];
}
June 03, 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"
 ];
}