This tutorial is about compiling code in C#. This focuses on how to write a simple code, compile the code and run a console application

Don't forget to check out our site http://howtech.tv/ for more free how-to videos!
http://youtube.com/ithowtovids - our feed
http://www.facebook.com/howtechtv - join us on facebook
https://plus.google.com/103440382717658277879 - our group in Google+

Introduction

Let us look into a simple program and how to compile code in C#. Lets open Visual C# 2008 Express Edition.

Step 1: Create New Project
First of all, open up a new program
Make sure you select the following file new project. console application. Type name as compile

Step 2: An Overview
Program.cs is the file where we will be writing our code. The following components build the complete class:
• The Main() Method
• The class Keyword
• The class name
• The using of predefined classes
C# classes are the primary building blocks of the language. C# also provides certain predefined set of classes and methods. These classes and methods provide various basic functionalities that you want to implement in your program. We use those predefined classes by using the keyword.

Next we have a class that can be defined by the user. Here the class Program is for our utility. Inside the class, we have the main method. Public static void Main (String[] args). So public is an access modifier, void is the return type and static is a type of method, which we will discuss detailed in further classes.
Main method is the entry point for a program. That is, the first line of code that a c# compiler looks for is a Main() method. You must include main() in your program to make it executable. The body of the Main() is again enclosed in delimiters.

Step 3: Insert Code
To print Hello World to the screen, we write in the body of the method, system.console.WriteLine("Hello World"); Note that the line ends with a semi colon. The dot character is used to access the method WriteLine which is present in the predefined class, console of the predefined namespace System.

Namespace is a collection of classes. It is a keyword, just like class and method. So this line can be rewritten as console.WriteLine(), if the statement 'using system' is included in the first line. This declares that you can refer to the classes defined in the namespace 'System'.

Step 4: Compile the code

To compile the code in C#, click build -- build solution or press F6.

Step 5: Run the Program
In C#, to run the program, click on debug - start debugging or use the shortcut, F5. You can see a console window must have flickered for a second and closed automatically. The console window does not stay longer as the command gets executed and the program stops.


Conclusion
To make the console window stay longer, add the following code snippet:
Console.ReadLine();
Once done with compiling the code in C#, run the program. This makes the console window to wait for the user input, thus helping in making the output visible.