Simple C # Console App in Visual Studio 2017, quit without showing result

0

I'm trying to run a simple program that writes "Hello world" in VS2017:

namespace OlaMundo
{
    class Program
    {
        static void Main()
        {
            int num;

            System.Console.WriteLine("Número :");

         num = System.Console.Read();

            System.Console.WriteLine(num);
        System.Console.WriteLine("Tecle enter para fechar...");

        System.Console.ReadLine();

    }
}
}

But when I run it, I encounter the following problem:

"OlaMundo.exe" (CLR v4.0.30319: DefaultDomain): Carregado "C:\WINDOWS\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll". Não é possível localizar ou abrir o arquivo PDB.
"OlaMundo.exe" (CLR v4.0.30319: DefaultDomain): Carregado "C:\Users\tiago\source\repos\C#_Hello_world\OlaMundo\OlaMundo\bin\Debug\OlaMundo.exe". Símbolos carregados.
O programa "[1688] OlaMundo.exe" foi fechado com o código 0 (0x0).

I have already disabled the " Just my code " option and also deleted the " bin " folder of the project and recompiled again. But I got no success.

    
asked by anonymous 17.02.2018 / 20:53

1 answer

1

Apparently there is nothing wrong, the console closes because the application has terminated its flow ... if you want to keep the window open and reading the "Hello, Wolrd", add a holding point as the input of some value .

Already your second problem is because you are not converting the type and using the wrong method. All entries via console are of type String, in your code you need to validate and convert to the expected type.

namespace OlaMundo
{
    class Program
    {
        static void Main(string[] args)
        {

            int num;
            Console.WriteLine("Número :");
            num = Convert.ToInt32(System.Console.ReadLine());

            Console.WriteLine(num);

            //Adicione esse trecho ao final da sua Main
            #if DEBUG
            Console.WriteLine("Tecle enter para fechar...");
            Console.ReadLine();
            #endif
        }
    }
}
    
19.02.2018 / 01:32