Hello World in C#

The Hello world is a basic program in any programming language when you learn any new programming language . In this first basic program, we will learn the following basic understanding in c#.

1. A class declaration.

2. Main Method.

3. Class declaration.

4. NameSpace declaration

5. Statement and Expression.

6. Print a statement

C# is a general-purpose, modern and object-oriented programming language pronounced as “C Sharp”. It was developed by Microsoft led by Anders Hejlsberg and his team within the .NET initiative and was approved by the European Computer Manufacturers Association (ECMA) and International Standards Organization (ISO). C# is among the languages for Common Language Infrastructure. C# is a lot similar to Java syntactically and is easy for users who have knowledge of CC++ or Java.

If you have ever learned a programming language, you know that they all start with the "Hello, world!" example, and who are we to break such a fine tradition? Start Visual Studio Community (introduced in the last chapter), and select File -> New -> Project. From the project dialog, select the Console App (.NET framework). This is the most basic application type on a Windows system, but it's great for learning the language. Once you click Ok, Visual Studio creates a new project for you, including a file called Program.cs. This is where all the fun is, and it should look something like this:

Hello World.PNG


  • using System: System is a namespace which contains the commonly used types. It is specified with a using System directive.

  • namespace HelloWorldApp: Here namespace is the keyword which is used to define the namespace. HelloWorldApp is the user-defined name given to namespace. For more details, you can refer to C# | Namespaces

  • class ConsoleApp9: Here class is the keyword which is used for the declaration of classes. ConsoleApp9 is the user-defined name of the class.

  • static void Main(string[] args): Here static keyword tells us that this method is accessible without instantiating the class. void keyword tells that this method will not return anything. Main() method is the entry point of our application. In our program, Main() method specifies its behavior with the statement Console.WriteLine(“Hello World!”);.

  • Console.WriteLine(): Here WriteLine() is a method of the Console class defined in the System namespace.

  • Console.ReadKey(): This is for the VS.NET Users. This makes the program wait for a key press and prevents the screen from running and closing quickly.