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);
}
}
}
You need to add another indexer. You’ve initialized
m_gridas a 3-dimentional array. So any first-level element withinm_gridis a 2-dimensional array. And you’re trying to set one of those elements to a 1-dimensional array:In the above code,
m_grid[gridIndexX]is of typeArrayList[][], so you have a type mis-match.You’ll need to set it to the proper type:
I don’t know if this alone will solve your problem, because it’s difficult to discern what this code is actually supposed to do. (Indeed, if you’re not sure what parts of your code are what dimensionality of arrays, I’m not sure if you even know what this code is supposed to do…)