【发布时间】:2015-09-12 10:00:27
【问题描述】:
目标是将一些 Tile 对象和自定义属性复制到 2D 数组中,但是我得到了意想不到的结果:
for (int i = 0; i<3; i++)
{
for (int j = 0; j<3; j++)
{
TileList[i][j] = Tiles[3];
//the goal is the overwrite the MapX and MapY fields of each element of the new Array
TileList[i][j].MapX = i;
TileList[i][j].MapY = j;
}
}
在打印出每个元素的值后,每个元素的每个 MapX 和 MapY 字段都应该有自己单独的值,但是对于 2d 数组中的每个图块对象引用,MapX 和 MapY 都设置为 3。
【问题讨论】: