So I have this array:
int[ ][ ] Array= new int[ ][ ] {
new int[ ] {1,2},
new int[ ] {2,2},
new int[ ] {2,1}
}
If I try sizeof(Array) it works, but sizeof(Array[0]) does not. Why?
So I have this array:
int[ ][ ] Array= new int[ ][ ] {
new int[ ] {1,2},
new int[ ] {2,2},
new int[ ] {2,1}
}
If I try sizeof(Array) it works, but sizeof(Array[0]) does not. Why?
sizeof returns you the size of a certain type:
If you want to know the number of elements in an array, you need to call length for the array:
And I’d suggest using a int[,] Array instead of an int[ ][ ], assuming each rank is the same length
Then you get the length with myArray.GetLength(int dimension)
Thank you ! really helpful!
@hpjohn Does that work from Array[ ][ ][ ]?
Also why did you suggest that?
Personal preferrence, on syntax niceness.
But read this and judge for yourself
http://www.dotnetperls.com/jagged-2d-array-memory
int[×][y][z] can be int[x,y,z]