这段代码在这一行给了我这个错误:“无法将类型 ArrayList[] 隐式转换为 ArrayList[][]”:m_grid[gridIndexX] = new ArrayList[Height];
但是我该如何以另一种方式做到这一点?当 m_grid 数组是二维数组时,它可以工作,但作为 3 维数组,它不起作用。谢谢您的帮助。
private ArrayList[][][] m_grid;
private void initialize() {
Width = 5;
Height = 5;
Depth = 5;
m_grid = new ArrayList[Width][][];
}
public void Refresh(ref ArrayList particles) {
m_grid = null;
m_grid = new ArrayList[Width][][];
if (particles != null) {
for (int i = 0; i < particles.Count; i++) {
FluidParticle p = (FluidParticle) particles[i];
int gridIndexX = GetGridIndexX(ref p);
int gridIndexY = GetGridIndexY(ref p);
int gridIndexZ = GetGridIndexZ(ref p);
// Add particle to list
if (m_grid[gridIndexX] == null) {
m_grid[gridIndexX] = new ArrayList[Height];
}
if (m_grid[gridIndexX][gridIndexY][gridIndexZ] == null) {
m_grid[gridIndexX][gridIndexY][gridIndexZ] = new ArrayList();
}
m_grid[gridIndexX][gridIndexY][gridIndexZ].Add(i);
}
}
}