C# Hello World!

Tutorials PanelPosted by

It’s has became a tradition to start the first programming language lesson with the famous “Hello World!” program. The program simply prints the string “Hello world” in the output window.
To get started, open visual studio, select new, C# Program.

using System;

namespace myfirstCSharpProgram
{
    class HelloWorld
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello world!");
            Console.ReadKey()
        }
    }
}

As simple as it appears, the program will prints out the string “hello world as shown below:

 Hello World!

You can run the program by hitting F5, or simply by clicking on the run button located in the command menu ().

The “using” keyword is used to include a namespace to your program. We will discuss namespaces in details later in this tutorial. The next line “Namespace myfisrtprogram” is to declare a new namespace, which is a collection of classes that can be used anywhere in your project.

In our case, our namespace has one class, which is the helloWorld class. Now the main method is the entry point of the program which takes the argument “args” as an input (we don’t have to provide any arguments in the Hello world Example). Then it will write “Hello world” to the output by using the function WriteLine. The console.ReadKey() waits for the user to press a key before to exit the program.

Leave a Reply