Array initialisation: What's wrong?

  • Thread starter Thread starter Axel Dahmen
  • Start date Start date
A

Axel Dahmen

I don't get it. Within a function I want to define a constant array of
strings. But the compiler gives me error CS0133: "The expression being
assigned to 'dbParams' must be constant".

What am I doing wrong here:


private string myFunc()
{
const string[,] dbParams={{"tas", "tbx"}
,{"twe", "dg"}
,{"bira", "dfh"}
,{"we", "strh"}
,{"yaz", "ask"}
};

...
}


TIA,
Axel Dahmen
 
I don't get it. Within a function I want to define a constant array of
strings. But the compiler gives me error CS0133: "The expression being
assigned to 'dbParams' must be constant".

My guess is that arrays cannot be constant, ever, since they're
reference types that have to be allocated on the heap (even though you
can omit the "new" as a convenience). So it's readonly, not const.
 
Back
Top