2

プログラムを作成してdoubleを使用していました。解析して、文字列が数値かどうかを確認してください。

class Game{ // declares the class
    private static string[,] board = new string[3, 3]{
                                          {" ", " ", " "}, // top row
                                          {" ", " ", " "}, // middle row
                                          {" ", " ", " "}  // bottom row
                                      };


private static void print(){
    System.Console.WriteLine("\n {0} | {1} | {2} ", board[2, 0], board[2, 1], board[2, 2]);
    System.Console.WriteLine("------------");
    System.Console.WriteLine(" {0} | {1} | {2} ", board[1, 0], board[1, 1], board[1, 2]);
    System.Console.WriteLine("------------");
    System.Console.WriteLine(" {0} | {1} | {2} \n", board[0, 0], board[0, 1], board[0, 2]);
}

private static void calculateMoves(){
    System.Console.Write("The possible moves are: ");
    int n = 1; // this is used to list all possible moves.
    for (int i = 0; i < 3; i++){
        for (int j = 0; j < 3; j++){
            if (board[i, j] == " "){
                System.Console.Write("{0} ", n);
            }
            n++;
        }
    } // end print possible moves.
    System.Console.WriteLine(); // go to next line
}

public static bool isNumeric(string s){ // this functions checks if the input string is numeric.
    double Result;
    return double.TryParse(s, out Result);
}        

static void Main(){ 
// the main function, the program starts from (this is a method declartion)
    System.Console.WriteLine("\nWelcome to theelitenoob's simple tic tac toe game!");
    System.Console.WriteLine("Written in C#, released under the GPL.");
    System.Console.WriteLine("The board is 3 by 3, Type a number to place a move there.");
    System.Console.WriteLine("So 1 is bottom left and 9 is top right, like a standard keypad.\n");
    int winner = 0; // there is no winner yet.
    // write players piece
    System.Console.WriteLine("You are x");
    // create the board
    int move; // move number
    string input; // the string from which move number is got from
    while(winner == 0){
        print();
        calculateMoves();
        System.Console.Write("Please type in a move number: ");
        input = System.Console.ReadLine();
        if(!isNumeric(input)){ // check if input is *not* numeric
            // if it isn't, print message and ask for input again.
            System.Console.WriteLine("Thats not a valid move, Try again!");
            continue;
        }
        move = System.Convert.ToInt32(input);
        /**/
        if (move == 1 && board[0, 0] == " ")board[0, 0] = "x";
        if (move == 2 && board[0, 1] == " ")board[0, 1] = "x";
        if (move == 3 && board[0, 2] == " ")board[0, 2] = "x";
        if (move == 4 && board[1, 0] == " ")board[1, 0] = "x";
        if (move == 5 && board[1, 1] == " ")board[1, 1] = "x";
        if (move == 6 && board[1, 2] == " ")board[1, 2] = "x";
        if (move == 7 && board[2, 0] == " ")board[2, 0] = "x";
        if (move == 8 && board[2, 1] == " ")board[2, 1] = "x";
        if (move == 9 && board[2, 2] == " ")board[2, 2] = "x";
    } // end while loop
}

}

でも。エラーが表示されます。コンパイルしようとすると、msdnをすべて調べて、googleを検索しましたが、修正方法がわかりません。

これは私が得るエラーです:

tictactoe.cs(33,23): error CS1501: No overload for method 'TryParse' takes '2' arguments

なぜこれが起こるのか、そしてそれを修正する方法を誰かが知っていますか?

4

2 に答える 2

2

Double.TryParseメソッドには2つのオーバーロードがあります。

前者は.NET1.1以降に存在し、後者は.NET2.0で導入されました。


Monoには2つのコンパイラが付属しています。

  • mcs-ジェネリックなしで最新の.NETバージョンを実装することを目的としています(<.NET 2.0)

  • gmcs-ジェネリックスを使用して最新の.NETバージョンを実装することを目的としています(> = .NET 2.0)

したがって、mcsは新しいオーバーロードについて知りません。それはかなり時代遅れであり、afaikは積極的に維持されていません。

最新のC#および.NETバージョンにはgmcsを使用してください。

于 2011-07-15T02:31:20.077 に答える
-1

大文字のDでDouble.TryParseと言わなければならないようです。

于 2011-07-15T02:02:32.617 に答える