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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top