我有一个整数,我想将其转换为 3 个整数作为 3d 数组的索引,这是我正在做的事情的一个例子。
byte[,,] array = new byte[XSize, YSize, ZSize];
int i = 0;
//other code
array[#,#,#] = cur;
//other code
我不知道如何从 i 中获取 #,#,# 的正确数字。
最佳答案
假设您要遍历 Z、Y、X。. .
int zDirection = i % zLength;
int yDirection = (i / zLength) % yLength;
int xDirection = i / (yLength * zLength);
关于c# - 将 1d 数组索引转换为 3d 数组索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11316490/