Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C# Program Structure

C# Program Structure

Before we learn the basic building blocks of the C# programming language, let's first look at the minimal program structure of C# as a reference for the following chapters.

C# Hello World Example

A C# program mainly consists of the following parts:

C# files have the extension .cs.

The following creates a test.cs file, which contains simple code that prints "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 code above is compiled and executed, it produces the following result:


Hello World

Let's look at the various parts of the program above:

The following points are worth noting:

Compiling & Executing a C# Program

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

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