gpt4 book ai didi

c# - 将 1d 数组索引转换为 3d 数组索引?

转载 作者:行者123 更新时间:2023-11-30 13:13:24 25 4
gpt4 key购买 nike

我有一个整数,我想将其转换为 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com