Here we will learn how to create first c# hello world program in visual studio with examples, create first console application using c# programming language in visual studio with examples.
By using Visual Studio, we can easily create a Hello World Program or Console Application in C# programming language based on our requirements.
In previous chapter, we explained how to Download and Install Visual Studio on Windows Machine. In case, if you are not installed a visual studio, then follow the instructions to install visual studio otherwise open your visual studio.
To create a new application in visual studio, go to Menu bar, select File à New à select a Project like as shown below.
Once you click on Project, a new popup will open in that select Visual C# from the left pane and choose Console App. In the Name section give any name for your project and select appropriate Location path to save your project files and click OK like as shown below.
Once we click on OK button, a new console application will be created like as shown below. In case Program.cs file not opened in your code editor, open the Solution Explorer menu in right side and open your Program.cs file code by double clicking on it.
If you observe above image, by default the application contains a Main() method because the console applications in c# programming language will always starts from the Main() method of program class.
Now replace your Program.cs file code like as shown below to display “Hello World” message.
static void Main(string args)
Console.WriteLine("Press Any Key to Exit.");
If you observe above code, we used a lot of parameters to implement “Hello World” program in c#. In next section, we will learn all the parameters in detailed manner.
Following diagram will illustrate the type of parameters which we used in our c# program in detailed manner.
Now we will go through each step of our c# program and learn each parameter in detailed manner.
using System is the .NET Framework library namespaces and we used
using keyword to import
system namespace to use existing class methods such WriteLine(), ReadLine(), etc. By default the .NET Framework provides a lot of namespaces to make the application implementation easily.
The namespace is a collection of classes and classes are the collection of objects and methods.
namespace HelloWorld is the main namespace of our application and by default our application classes will be a part of it.
class Program is used to define a class (Program) in namespace (Helloworld). The class (Program) will contain all the variables, methods, etc. and we can define more than one class in same namespace based on our requirements.
static void Main(string args)
static void Main(string args) is used to define a method in our class (Program).
statictells us that, the main method can be accessible without instantiating the class (Program).
voidtells us that, what this method should return.
argsand it is useful to send command line arguments as a text strings for our main method.
Console.WriteLine() / ReadLine()
Console.ReadLine() methods are used to write a text to console and read the input from console.
Console is a class of .NET Framework namespace
System and WriteLine() and ReadLine() are the methods of
To see the output of our Hello World C# Program, we need to compile and run the application by pressing either Ctrl + F5 or click on Start option in the menu bar like as shown below.
Once we click on Start option or Ctrl + F5, our program will get compiled and show the result like as shown below.
This is how we can create and execute the applications in c# programming language using visual studio based on our requirements.