Module 3    C# - Program Structure

Before we study basic building blocks of the C# programming language, let us look at a bare minimum C# program structure so that we can take it as a reference in upcoming chapters.

Creating Hello World Program

A C# program consists of the following parts −

Let us look at a simple code that prints the words "Hello World" −

Live Demo
using System;

namespace HelloWorldApplication {
   class HelloWorld {
      static void Main(string[] args) {
         /* my first program in C# */
         Console.WriteLine("Hello World");
         Console.ReadKey();
      }
   }
}

When this code is compiled and executed, it produces the following result −

Hello World

Let us look at the various parts of the given program −

It is worth to note the following points −

Compiling and Executing the Program

If you are using Visual Studio.Net for compiling and executing C# programs, take the following steps −

You can compile a C# program by using the command-line instead of the Visual Studio IDE −