Section 1. Introduction. 1.6 Your first program – Hello world
There are two ways to start Visual Studio Community 2019 – from Windows Start and from Visual Studio installer.
Click on Launch button to start Visual Studio Community 2019. If you need to install additional components click on Modify.

Go to Start and click on Visual Studio 2019.

Click on Create a new project.

Choose Console Application from the list and click on the Next button.


Select the target Framework and click on Create button.

Visual Studio will automatically generate some code for your project.

Run the program by pressing the F5 button on your keyboard (or click on “Debug” -> “Start Debugging“). This will compile and execute your code.

The result will look something to this.

Congratulations! You have now written and executed your first C# program.
Your first program explained
Line 1: using System means that we can use classes from the System namespace.
Line 2: A blank line. C# ignores white space but multiple lines makes the code more readable.
Line 3: namespace is used to organize your code, and it is a container for classes and other namespaces.
Line 4: The curly braces {} marks the beginning and the end of a block of code.
Line 5: class is a container for data and methods, which brings functionality to your program. Every line of code that runs in C# must be inside a class. In our example, we named the class Program.
Line 7: Another thing that always appear in a C# program, is the Main method. Any code inside its curly brackets {} will be executed. You don’t have to understand the keywords before and after Main. You will get to know them bit by bit while reading this tutorial.
Line 9: Console is a class of the System namespace, which has a WriteLine() method that is used to output (print) text. In our program it will output “Hello World!“.
If you omit the using System line, you would have to write System.Console.WriteLine() to print (output) text.
Please note, that:
- Every C# statement ends with a semicolon ;
- C# is case-sensitive: “myClass” and “myclass” has different meaning.
- Unlike Java, the name of the C# file does not have to match the class name, but they often do (for better organization).
- When saving the file, save it using a proper name and add “.cs” to the end of the filename. To run the example above on your computer, make sure that C# is properly installed.
- The most common method to output something in C# is WriteLine(), but you can also use Write(). The difference is that WriteLine() prints the output on a new line each time, while Write() prints on the same line (you should remember to add spaces when needed, for better readability):
3 ways to run a C# program
There are 3 ways to compile and execute a C# program:
- You can use an online C# compiler. You can use various online IDE which can be used to run C# programs without installing (Jdoodle, .Net Fiddle, Replit, Codingrooms etc.)
- You can use Visual Studio IDE.
- You can use Command-Line. It applies to .NET Framework projects only. You can also use command-line options to run a C# program. Below steps demonstrate how to run a C# program on Command line in Windows Operating System: You need open a text editor like Notepad or Notepad++, write the code in the text editor and save the file with .cs extension, open the cmd (Command Prompt) and run the command csc to check for the compiler version.The csc.exe executable file is usually located here – C:\Windows\Microsoft.NET\Framework\<Version>



To compile the code type csc filename.cs on cmd. If your program has no error then it will create a filename.exe file in the same directory where you have saved your program. Suppose you saved the above program as helloworld.cs. So you will write csc helloworld.cs on cmd. This will create a hellowolrd.exe.

You have two ways to execute the hellowolrd.exe. First, you have to simply type the filename i.e helloworld on the cmd and it will give the output. Second, you can go to the directory where you saved your program and there you find helloworld.exe. You have to simply double-click that file and it will give the output.


How to modify PATH in MS Windows 10 (add path to csc.exe)
Click on Start and then click on Settings.

Click on Settings.

Click on About and then click on Advanced system settings.

Click on Environment Variables.. button.

Select Path in the User variables for … field and click on Edit… button. Then click on Browse.. button and look for C:\Windows\Microsoft.NET\Framework\<Version> or C:\Windows\Microsoft.NET\Framework64\<Version> . Click on OK button.

Click on OK button. Congrats. You did it, the way to csc.exe added to the PATH. You can close all windows now.
Wrapping out
The Hello World! program is the most basic and first program when you dive into a new programming language. This program simply prints the Hello World! on the output screen.
Thank you for reading.
Check for more tutorials at acoptex.lt.
Check for Arduino and Raspberry Pi projects on our website acoptex.com.
Section 1. Introduction. 1.1 C# programming language
Section 1. Introduction. 1.2 Introduction to .NET Framework
Section 1. Introduction. 1.3 C# versions history
Section 1. Introduction. 1.4 C# vs Java
Section 1. Introduction. 1.5 C# get started
Section 1. Introduction. 1.6 Your first program – Hello world
Section 1. Introduction. 1.7 C# identifiers and keywords
Section 2. Fundamentals. 2.1 C# Comments