Как вывести значения из этих двух подпрограмм?

Я пытаюсь вызвать XCoordinate и YCoordinate и сетку, чтобы отобразить их в основном, как мне это сделать?

public static void DisplayBoard(char[,] Board)
    {
        string[,] grid = new string[3, 3] {{"   ","   ","   "},
                                           {"   ","   ","   "},
                                           {"   ","   ","   "}};

        string board = System.IO.File.ReadAllText("H:\\BoardGame.txt");
        Console.WriteLine(grid);           
    }


    public static void GetMoveCoordinates(ref int XCoordinate, ref int YCoordinate)
    {
        int CommaLocation;
        bool GameHasBeenWon = false;
        string CoordinatesInput;
        string XChar, YChar;
        while (GameHasBeenWon == false)
        {
            try
            {
                Console.Write("Enter your coordinates: (x,y) ");
                CoordinatesInput = Console.ReadLine();
                CommaLocation = CoordinatesInput.IndexOf(",".ToString());
                XChar = CoordinatesInput.Substring(CommaLocation - 1);
                YChar = CoordinatesInput.Substring(CommaLocation + 1);
                XCoordinate = int.Parse(XChar);
                YCoordinate = int.Parse(YChar);
            }
            catch
            {
                Console.WriteLine("Invalid Input- Please Try Again");
            }
        }
    }
}

person Pavvel    schedule 13.12.2016    source источник
comment
Возможный дубликат Как распечатать 2D-массив на консоли в C#   -  person Mong Zhu    schedule 13.12.2016


Ответы (2)


Вы называете это так:

int x = 0;
int y = 0;
GetMoveCoordinates(ref x, ref y)
Console.WriteLine("Move was {0},{1}",x,y)
person Jamiec    schedule 13.12.2016

Что ж...

string[,] grid = new string[3, 3] {{"   ","   ","   "},
                                       {"   ","   ","   "},
                                       {"   ","   ","   "}};

public void AddMove(int x, int y, string p)
{
    grid(x,y) = $" {p} ";
    Console.SetCursorPosition(0,0)
    for(int i=0;i<3;i++) 
    {
        for(int j=0;j<3;j++) 
        {
            Console.Write(grid(i,j));
        }
        Console.Write("\n");
    }

}
person Ewan    schedule 13.12.2016