c# - Using TryParse with a double shows an overload error? -
c# - Using TryParse with a double shows an overload error? -
i writing programme , using double.try parse check if string numeric.
class game{ // declares 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; // used list possible moves. (int = 0; < 3; i++){ (int j = 0; j < 3; j++){ if (board[i, j] == " "){ system.console.write("{0} ", n); } n++; } } // end print possible moves. system.console.writeline(); // go next line } public static bool isnumeric(string s){ // functions checks if input string numeric. double result; homecoming double.tryparse(s, out result); } static void main(){ // main function, programme starts (this method declartion) system.console.writeline("\nwelcome theelitenoob's simple tic tac toe game!"); system.console.writeline("written in c#, released under gpl."); system.console.writeline("the board 3 3, type number place move there."); system.console.writeline("so 1 bottom left , 9 top right, standard keypad.\n"); int winner = 0; // there no winner yet. // write players piece system.console.writeline("you x"); // create board int move; // move number string input; // string move number got while(winner == 0){ print(); calculatemoves(); system.console.write("please type in move number: "); input = system.console.readline(); if(!isnumeric(input)){ // check if input *not* numeric // if isn't, print message , inquire input again. system.console.writeline("thats not valid move, seek 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 }
}
however. shows me error: whenever seek compile, went through of msdn , searched google, can't figure out how fix.
this error get:
tictactoe.cs(33,23): error cs1501: no overload method 'tryparse' takes '2' arguments
does know why happens , how prepare it?
the double.tryparse method has 2 overloads:
tryparse(string, numberstyles, iformatprovider, double)
tryparse(string, double)
the former exists since .net 1.1, while latter introduced in .net 2.0.
mono ships 2 compilers:
mcs -- aims implement latest .net version without generics (< .net 2.0)
gmcs -- aims implement latest .net version generics (>= .net 2.0)
so mcs doesn't know new overload. it's pretty outdated , afaik not actively maintained.
use gmcs latest c# , .net version.
c# methods method-overloading tryparse
Comments
Post a Comment