我知道它们用于存储数据,但我很难理解如何在程序中使用它们.
另外,我发现这个网站有一个俄罗斯方块克隆教程(缺少实际的教程).它使用数组,但我无法理解它是如何工作的.
这是代码的一个例子 -
public int[, ,] TShape = new int[4, 4, 2]
{
{{1, 0}, {0, 1}, {1, 1}, {2, 1}},
{{1, 0}, {0, 1}, {1, 1}, {1, 2}},
{{0, 0}, {1, 0}, {2, 0}, {1, 1}},
{{0, 0}, {0, 1}, {1, 1}, {0, 2}}};
Run Code Online (Sandbox Code Playgroud)
可能是因为我看起来太难了,或者有些东西我不理解它?
如果以这种方式格式化将更清楚:
public int[, ,] TShape = new int[4, 4, 2]
{
{ {1, 0}, // <- this is int[2]
{0, 1},
{1, 1},
{2, 1} }, // <- the last four lines are an int[4,2]
{ {1, 0},
{0, 1},
{1, 1},
{1, 2} }, // <- another int[4,2]
{ {0, 0},
{1, 0},
{2, 0},
{1, 1} }, // <- third int[4,2]
{ {0, 0},
{0, 1},
{1, 1},
{0, 2} } // <- fourth and last int[4,2]
}; // <- The whole thing is int[4, 4, 2]
Run Code Online (Sandbox Code Playgroud)