这段代码工作正常:
var newArray = new Rectangle[newHeight, newWidth];
for (int x = 0; x < newWidth; x++)
for (int y = 0; y < newHeight; y++)
newArray[y, x] = (x >= width) || (y >= height) ? Rectangle.Empty : tiles[y, x];
Run Code Online (Sandbox Code Playgroud)
但我没有太多运气用Array.Copy取代它.基本上,如果调整大小的数组较大,则只需在边缘添加空白矩形.如果它小,那么它应该切断边缘.
这样做时:
Array.Copy(tiles, newArray, newWidth * newHeight);
它弄乱了阵列,它的所有内容都变得混乱,并且不保留它们的原始索引.也许我只是有一个脑力计或其他什么?