How to modify a foreach iteration variable from within foreach loop?

后端 未结 4 611
独厮守ぢ
独厮守ぢ 2021-01-04 02:18

When I try to do this...

Item[,] array = new Item[w, h];  // Two dimensional array of class Item, 
                                 //   w, h are unknown at          


        
4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-04 03:13

    Not knowing the size isn't a problem:

    for (int i = 0; i < twoDimArray.GetLength(0); i++)
    {
        for (int j = 0; j < twoDimArray.GetLength(1); j++)
        {
            twoDimArray[i, j] = ...
        }
    }
    

提交回复
热议问题