Easy Tutorial
❮ Csharp Queue Csharp Collection ❯

C# Program Structure

Before we delve into the fundamental building blocks of the C# programming language, let's first look at the minimal structure of a C# program to serve as a reference for the upcoming chapters.

C# Hello World Example

A C# program generally includes the following parts:

The file extension for C# files is .cs.

Below is a test.cs file that contains simple code to print "Hello World":

test.cs File Code:

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

When the above code is compiled and executed, it produces the following result:

Hello World

Let's examine the various parts of the program:

WriteLine is a method of the Console class defined in the System namespace. This statement displays the message "Hello World" on the screen.

A few important points to note:

Compiling & Executing C# Program

If you are using Visual Studio.Net to compile and execute a C# program, follow these steps:

You can also compile a C# program using the command line instead of Visual Studio IDE:

❮ Csharp Queue Csharp Collection ❯