哟。我是游戏开发的初学者,我正在制作一个控制台tictactoe游戏,我试图将棋盘网格从我的游戏的棋盘类传递到主类,因为我想把棋盘放在它自己的类中。我制作了一个二维数组来保存棋盘的字符,但我无法返回它,错误是“无法将类型'string [,]'隐式转换为'string'。
private int maxRow = 3;
private int maxColumn = 3;
private string[,] boardGrid = new string[3, 3]; //create the game board grid
//Initialise board method
public string InitBoard () //make an object of the board class, returns a 2d array because the board is essentially a grid
{
//initialise board
for (int row = 0; row < maxRow; row++)
{
for (int column = 0; column < maxColumn; column++)
{
boardGrid [row, column] = ".";
}
}
return boardGrid; //<---[The problem happens here!]
}
这是主类的代码。
public static void Main (string[] args)
{
Board ticTacToeBoard = new Board ();
ticTacToeBoard = ticTacToeBoard.InitBoard ();
ticTacToeBoard.DisplayBoard (ticTacToeBoard);
}
我在这方面找不到任何其他问题,但如果有任何问题,请随时指出我。干杯!