Array initialisation: What's wrong?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Axel Dahmen

    #1

    Array initialisation: What's wrong?

    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


  • Christoph Nahr

    #2
    Re: Array initialisation: What's wrong?

    On Sat, 15 Nov 2003 19:56:41 +0100, "Axel Dahmen"
    <NO_SPAM@NoOneK nows.de> wrote:
    [color=blue]
    >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".[/color]

    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.
    --
    Stay ahead in World of Warcraft with expert guides, latest patch news, class tips, dungeon strategies, PvP builds, and The War Within updates—all in one place.

    Comment

    Working...