I'm learning, so it's a basic question

0

I would like to know why, when the program was run, it does not even show Console.WriteLine("nome: {0}", nome); on the screen?

        string endereço, cpf, telefone, nome;

        Console.WriteLine("Digite o nome. ");
        nome = Console.ReadLine();


        Console.WriteLine("Digite o endereço.");
        endereço = Console.ReadLine();

        Console.WriteLine("Digite o CPF.");
        cpf = Console.ReadLine();


        Console.WriteLine("Digite o telefone");
        telefone = Console.ReadLine();

        Console.WriteLine("nome: {0}", nome);
        Console.WriteLine("endereço: {0}", endereço);
        Console.WriteLine("CPF: {0}", cpf);
        Console.WriteLine("telefone: {0}", telefone);
    
asked by anonymous 10.08.2018 / 22:50

2 answers

3

When executing the program it performs WriteLine but leaves immediately

You can wait for a key to be pressed before leaving

            string endereço, cpf, telefone, nome;

            Console.WriteLine("Digite o nome. ");
            nome = Console.ReadLine();


            Console.WriteLine("Digite o endereço.");
            endereço = Console.ReadLine();

            Console.WriteLine("Digite o CPF.");
            cpf = Console.ReadLine();


            Console.WriteLine("Digite o telefone");
            telefone = Console.ReadLine();

            Console.WriteLine("nome: {0}", nome);
            Console.WriteLine("endereço: {0}", endereço);
            Console.WriteLine("CPF: {0}", cpf);
            Console.WriteLine("telefone: {0}", telefone);


            //assim execução vai ficar suspensa até que pressione uma tecla


            Console.WriteLine("Prima uma tecla para Sair");
            Console.ReadKey();
    
10.08.2018 / 23:01
1

I even ran a test with your code and it worked normally as the print below, I do not know how you were running it, if you just gave 2 clicks on the executable, whether it was running directly through Visual Studio or if you went on the console cmd) and typed the .exe name to run the program. In the latter option you would see that it works normally, because it would not close the screen at the end of the execution. If you add a simple Console.ReadLine (); at the end of the code you will see that it stops at that line (waiting for an enter) after displaying the values, and only after giving the enter will it close the application window (if it were running on the console it would keep the console window open).

stringendereço,cpf,telefone,nome;Console.WriteLine("Digite o nome. ");
        nome = Console.ReadLine();


        Console.WriteLine("Digite o endereço.");
        endereço = Console.ReadLine();

        Console.WriteLine("Digite o CPF.");
        cpf = Console.ReadLine();


        Console.WriteLine("Digite o telefone");
        telefone = Console.ReadLine();

        Console.WriteLine("nome: {0}", nome);
        Console.WriteLine("endereço: {0}", endereço);
        Console.WriteLine("CPF: {0}", cpf);
        Console.WriteLine("telefone: {0}", telefone);


        Console.ReadLine();
    
10.08.2018 / 23:07