gpt4 book ai didi

c# - 如何拥有 Column,Rows 数组(反之亦然)

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

制作生活游戏我需要一个 30x20 (X * Y) 的网格。问题是(我对此有另一个问题)c# 数组是行、列。因此,当我使用 CursorPosition() 进行绘图时,我需要交换它,因为它首先需要列。有什么方法可以逆转它以便我可以像这样使用吗?

int [,] Array = new int[30,20];
Console.SetCursorPosition(29,19) // now its vice versa, I would need to use 19,29.

最佳答案

我认为这纯粹是概念性的(c# 数组既不是由开发人员决定的 row/col 或 col/row),归结为以深度优先或广度优先的方式迭代数组,例如

//Breadth-first
for(int x = 0; x < col.Length; x++)
{
for(int y = 0; y < row.Length; y++)
{
}
}

//Depth-first
for(int y = 0; y < row.Length; y++)
{
for(int x = 0; x < col.Length; x++)
{
}
}

关于c# - 如何拥有 Column,Rows 数组(反之亦然),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4253567/

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