tags:

views:

98

answers:

1

How I do Initialize this:

public const int[][,] Map = ...

I would like to do something like this:

public const int[][,] Map = {
    { // Map 1
        {1, 1, 1, 1},
        {1, 1, 1, 1},
        {1, 1, 1, 1},
        {1, 1, 1, 1},
    },
    { // Map 2
        {1, 1, 1, 1},
        {1, 0, 0, 1},
        {1, 0, 0, 1},
        {1, 1, 1, 1},
    },
    // etc.
};

I don't want to create an int[,,] Map, because somewhere else I want to do:

loader.Load(Map[map_numer]); // Load method recieve an int[,]
+7  A: 
int[][,] a = new int[][,]
{
    new int[,]
    {
        {1, 1, 1, 1},
        {1, 1, 1, 1},
        {1, 1, 1, 1},
        {1, 1, 1, 1},

    },
    new int[,]
    {
        {1, 1, 1, 1},
        {1, 0, 0, 1},
        {1, 0, 0, 1},
        {1, 1, 1, 1},
    }
};
Overdose
Thanks!. It works, but `Map` can't be a `const` (The compiler throw me an error if `Map` is `const`
unkiwii
you may try using keyword readonly instead
Overdose
`readonly`. Ok! I'm new to C# and I've never seen the `readonly` keyword, I have to remeber this next time.
unkiwii