1 回答

TA貢獻(xiàn)1772條經(jīng)驗(yàn) 獲得超8個(gè)贊
您可以嘗試嵌套循環(huán):
for (int i = 0; i < titles.GetLength(0); ++i)
for (int j = 0; j < titles.GetLength(1); ++j)
titles[i, j] = new BoardTile();
編輯:如果嵌套循環(huán)太復(fù)雜且不可讀,請(qǐng)嘗試切換到鋸齒狀數(shù)組,即數(shù)組數(shù)組BoardTile tiles[][];- 從2D one BoardTile tiles[,],例如
// created and initialized jagged array
BoardTile tiles[][] = Enumerable
.Range(size.Y) // size.Y lines
.Select(y => Enumerable // each line is
.Range(size.X) // size.X items
.Select(x => new BoardTile()) // each of them is BoardTile()
.ToArray()) // materialized as array
.ToArray(); // all arrays are array of array
- 1 回答
- 0 關(guān)注
- 105 瀏覽
添加回答
舉報(bào)