This code gives me this error:"Cannot implicitly convert type ArrayList[] to ArrayList[][]" at this line: m_grid[gridIndexX] = new ArrayList[Height]; But how can i do that in another way? When m_grid array is a two dimensional array it works but as a three dimensional array it doesn't work.Thanks for help.
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);
}
}
}
ArrayList. What you have is a three-dimensional Array of ArrayLists...List<T>instead of the outdatedArrayList. They avoid boxing and unboxing and the compiler can perform type checks on them. They are also a lot more readable which makes it easier to work with.