Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initialize int[][,] in C#

Tags:

arrays

c#

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[,]
like image 843
Lucas Gabriel Sánchez Avatar asked Dec 16 '25 14:12

Lucas Gabriel Sánchez


1 Answers

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},
    }
};
like image 107
Overdose Avatar answered Dec 19 '25 04:12

Overdose



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!