user2326369
user2326369

Reputation:

Don't understanding this instantiate

I'm trying to translate a flash code into c#. I'm not familiar with flash so I'm having some problems. I have fix all problems but this because I don't understand what is.

private var map:Array<Array<Tile> = new Array<Array<Tile>>();

Is this a list of list? It's used like a bidimensional array but I don't think that this is an array.

Example:

    for (x in 0...Main.MAP_WIDTH) {
        map[x] = new Array<Tile>();
        for (y in 0...Main.MAP_HEIGHT) {
            // initialize a new tile
            map[x][y] = new Tile(Tile.DARK_WALL, true, true);

            // set location of tile based on array values
            map[x][y].setLoc(x, y);

            // add tile as a child so it will display
            addChild(map[x][y]);
        }
    }

Upvotes: 0

Views: 60

Answers (1)

gunr2171
gunr2171

Reputation: 17544

Is this a list of list?

Yes. It is. In c# it would be

private List<List<Tile>> map = new List<List<Tile>>();

There is a difference (in c# at least) for how you access array elements. If you did a multidimensional array it would look like this:

string[,] map2 = new string[2, 3];
map2[1, 3] = "aa";

With a list, because one array is a "member" (loose terminology) of the other, each has to be in it's own brackets.

map[2][4] = SomeTile();

Upvotes: 1

Related Questions