Input and Output via Keyboard and Screen

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

 

1 - Input by keyboard

To enter information using the keyboard, what we have 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 let us enter any value until we press enter.

But clearly, if we only receive the information and do nothing, we need to store it in a variable

String etradaTeclado = Console.ReadLine();

 

 

2 - Output to screen

Displaying information is very simple, we just have 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 piece of code we see to display in Console.WriteLine() is called string interpolation which we will see later in this course.

Finally, we put a Console.ReadKey() so that the execution of the code stops until a single character is entered 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

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

Buy me a coffee Invitame a un café