Last Updated:

Displaying a message on the screen and keyboard input in C# (sharp)


Let's start with the classics of the genre of learning the basics of programming: input and output to the screen!

To start writing code successfully, follow these steps:

  1. Open the Visual Studio development environment;
  2. Click on the "Create project..." button;
  3. In the hierarchy of all the features provided by the environment, select "Visual C#" -> "Console Application";
  4. Give your project a name at the bottom of the window, let's call it "Hello_World";
  5. Click "OK";
  6. You have a "classic beginning";

Actually, in this window, our training will take place. Here we will write the code!

Nothing needs to be washed at the moment, everything is needed here. You see the connected libraries in the first lines of the code, below is the so-called class and method of this class. Actually, in this very method we have to create magic.


To display some information or values of variables on the screen, you must use the output function.

Remember: for text data you need to use:

  1. Or single quotation marks ' - they contain only one character;
  2. Or double quotation marks " - they can contain as many characters as you like;
  3. Use either the first option or the second, otherwise you will get an error;

Let's display the offer "Hello World!".

Those who are learning programming for the first time saw a lot of incomprehensible and strange words, for example: "library", "namespace", "class", "class method" - do not be afraid, you are not stupid, these are really "things" that require certain knowledge. You will get them a little later, we will study all these terms in further lessons.

Run this code by pressing F5 or find the "debug" tab, and then "start debugging". Did you see a flashing black window? Well done! The program works!

The compiler has worked its own — it has run your code successfully. The trick is to tell the compiler "wait, take your time". To "tell" him, you need to use the keyboard input function.

"Wait, compiler!"

We need to tell the compiler to "wait" so that it doesn't quit the program without our permission.

Upgrade the code above so that we have time to read what is written.

Run the code for execution (by pressing F5 or find the "debug" tab, and there "start debugging").

Now you have the opportunity to read the inscription "Hello World!"! Now you can enter any abracadabra, but in fact, it is useless, just press the "Enter" key and the program will complete successfully.