Здравствуйте, ребята, можно ли ограничить размер массива, как в этом примере
![enter image description here](https://i.stack.imgur.com/ONmLa.png)
Теперь я хочу показать только 6 из них.
Что я сделал до сих пор, так это
CustomClass
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);
}
У меня есть все это значение ранее, прежде чем я выполню код обновления
![enter image description here](https://i.stack.imgur.com/wSVGr.png)
Теперь, когда я выполняю обновленный код, вот что я получил
![enter image description here](https://i.stack.imgur.com/jBLH5.png)
Ожидаемый результат должен быть следующим:
![enter image description here](https://i.stack.imgur.com/ckzVQ.png)
Внутри этого черного маркера должны быть показаны только эти двенадцать столбцов, потому что я объявил на своем
int[,] arrayRoad = bsb.GetRoad(12,6);