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

Asked

Viewed 70 times

0

I would like to know why then, when the programme has been implemented, it fails to show Console.WriteLine("nome: {0}", nome); onscreen?

        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);
  • 1

    While you are learning you can see a more modern way of doing: https://dotnetfiddle.net/qeOOI2

2 answers

3


When running the program it performs Writeline but exits immediately

You can wait for a keystroke 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();

1

I even did a test with your code and it worked normally according to the print below, I don’t know how you were running it, if you just gave 2 clicks on the executable, ran straight through Visual Studio or if you went to the console (cmd) and typed the name of . exe to run the program. On this last option you would see that it works normally as 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 on this line (waiting for a enter) after displaying the values, and only after you enter it will close the application window (if running on the console it would keep the console window open).

inserir a descrição da imagem aqui

        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);


        Console.ReadLine();

Browser other questions tagged

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