: 'The input string was not in a correct format. '

Asked

Viewed 32 times

0

Hello, I am developing a program that collects data entered by the console in c#, however, I come across this problem when I enter a value other than’s' here

char entry = (char)Console.Read();

        if(entry != 's' || entry != 'S')
        {
            SetupServer(); //chamo a função novamente
        }
        else
        {
            ;
        }

The error occurs in this part during the second call of this function:

Console.WriteLine("Insira a SUA porta: ");
        myPort = int.Parse(Console.ReadLine());

I will now post the full code, I hope you can help me:

static void SetupServer()
    {
        Console.Clear();

        int myPort, destinationPort;
        string destinationIP;

        Console.WriteLine("Insira a SUA porta: ");
        myPort = int.Parse(Console.ReadLine());

        Console.WriteLine("Insira a porta de DESTINO: ");
        destinationPort = int.Parse(Console.ReadLine());

        Console.WriteLine("Insira o IP de DESTINO: ");
        destinationIP = Console.ReadLine();

        Console.Clear();

        Console.WriteLine("Os dados estao corretos? [S/N] \n" +
                          "Sua porta: {0} \n" +
                          "Porta de Destino: {1} \n" +
                          "Ip de Destino: {2}",
                           myPort, destinationPort, destinationIP);

        char entry = (char)Console.Read();

        if(entry != 's' || entry != 'S')
        {
            SetupServer();
        }
        else
        {
            ;
        }
    }
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.