Input and Output via Keyboard and Screen

In this tutorial, we will see both how to input information into our application and how to display it.

 

1 - Keyboard Input

To enter information via the keyboard, all we need to do is write the following line of code

Console.ReadLine();

When we do this, if we press the play button in Visual Studio, it will allow us to enter any value until we press enter.

However, if we only receive the information, we’re not doing anything with it, so we need to store it in a variable

String etradaTeclado = Console.ReadLine();

 

 

2 - Output to Screen

Displaying information is very simple, we just need to use the statement Console.WriteLine(variable)

Therefore, we can make an example that asks the user for their name and displays it on the screen.

Console.WriteLine("Introudce tu nombre:");
string nombre = Console.ReadLine();
Console.WriteLine($"El nombre es {nombre}");
Console.ReadKey();

The code piece we see to display in Console.WriteLine() is called string interpolation which we will see further on in this course.

Finally, we put a Console.ReadKey() so that the code execution pauses until we enter a single character via the keyboard

This post was translated from Spanish. You can see the original one here.
If there is any problem you can add a comment bellow or contact me in the website's contact form

Uso del bloqueador de anuncios adblock

Hola!

Primero de todo bienvenido a la web de NetMentor donde podrás aprender programación en C# y .NET desde un nivel de principiante hasta más avanzado.


Yo entiendo que utilices un bloqueador de anuncios como AdBlock, Ublock o el propio navegador Brave. Pero te tengo que pedir por favor que desactives el bloqueador para esta web.


Intento personalmente no poner mucha publicidad, la justa para pagar el servidor y por supuesto que no sea intrusiva; Si pese a ello piensas que es intrusiva siempre me puedes escribir por privado o por Twitter a @NetMentorTW.


Si ya lo has desactivado, por favor recarga la página.


Un saludo y muchas gracias por tu colaboración

© copyright 2025 NetMentor | Todos los derechos reservados | RSS Feed

Buy me a coffee Invitame a un café