【发布时间】:2018-06-05 05:18:28
【问题描述】:
大家好,可以像这个例子一样限制数组大小
现在我只想展示其中的 6 个。
到目前为止我所做的是这个
自定义类
const int MAX = 104; // = 8 decks * 52 cards / 4cardsoneround
const int Y = 6;
int[,] arrayRoad = new int[Y, X];
public int[,] GetRoad(int x) {
arrayRoad = new int[x, 6];
return arrayRoad;
}
现在我像这样在我的 MainClass 上显示它
ScoreBoard bsb = new ScoreBoard();
private void Road()
{
bsb.makeRoad(history); // Road
int[,] arrayRoad = bsb.GetRoad(6); //<--- sample value 6
string s = "";
for (int y = 0; y < arrayRoad.GetLength(0); y++)
{
//just 27 for now
for (int x = 0; x < 28; x++)
{
s += string.Format("{0:D2}",arrayRoad[y, x]);
s += ".";
}
s += "\n";
}
Debug.Log(s);
}
这段代码的问题在于它给了我一个Array out of index
这可能吗??
更新
public int[,] GetRoad(int x = MAX,int y = Y) {
arrayRoad = new int[y, x];
return arrayRoad;
}
在我的Max = 104 和Y = 6 中的什么地方
int[,] arrayRoad = bsb.GetRoad(12,6); //12 rows and 6 in height
string s = "";
for (int y = 0; y < arrayRoad.GetLength(0); y++)
{
for (int x = 0; x < arrayRoad.GetLength(1); x++)
{
s += string.Format("{0:D2}",arrayRoad[y, x]);
s += ".";
}
s += "\n";
}
Debug.Log(s);
}
在我执行更新代码之前,我已经拥有了所有这些值
现在,当我执行更新后的代码时,这就是我得到的
预期的结果一定是这样的
在那个黑色标记里面,只有那十二列必须显示,因为我在我的上面声明了
int[,] arrayRoad = bsb.GetRoad(12,6);
【问题讨论】:
-
运行这段代码会发生什么?有可能吗?
-
它给了我一个
Out of Range错误。 -
arrayBigEyeRoad又是arrayRoad的错字吗? -
@RodrigoRodrigues 错字太多我很抱歉。天啊
-
预期结果是什么?