Noob c#. Trying to verify user input inside a method -


i´m using input inside loop (while). want verify input of user, inside method, , if not number should return again ask input. problem when try have restart program. can explain me how control code can go in code? much!

            console.writeline("efetue jogada ->");             string escolha = console.readline();              int verificaçaoescolha = escolhaverificacao(escolha);              if(valido == 1){             console.writeline("try again"); 

//method

    public static int escolhaverificacao(string a) {         int b;         int valido = 0;          try {             int.tryparse(a, out b);         }         catch (formatexception) {             valido = 1;         }         return valido;     } 

int32.tryparse doesn't rise exceptions. returns true if input has been converted integer

public static bool escolhaverificacao(string a)  {     int b;     return int.tryparse(a, out b); } 

and call

console.writeline("efetue jogada ->"); string escolha = console.readline();  bool verificaçaoescolha = escolhaverificacao(escolha); if(!verificaçaoescolha) {     console.writeline("try again"); } 

Comments