My Profile

Tuesday, January 25, 2011

Writing our first C# Program

We can write a program either by using an editor Visual Studio .net or under a Notepad also. when we write the program under visual studio it will implicitly save, compile and execute the code. whereas, in notepad we need to  manually save, compile and execute the program.

Writing a Program in Notepad:

Step 1: Open the notepad and write the following code in it.

class Example
    static void Main()
        System.Console.WriteLine("My First Program");

Save the program as Example.cs in the desired location.

Step 2: Compiling the program

To compile the program we were provided with a C# compiler that should be used from visual studi commant prompt. 
To use it  goto Start Menu --> Programs -->  MS Visual Studio --> Visual Studio Tools --> Visual Studio Command prompt.

After opening the command prompt, first move into the folder where your program has been saved and use the following statement to compile the program.

                                CSC  <filename>

eg: C:\CSharp\csc example.cs

Once the program gets compiled, it generates a file Example.exe in the same folder which contains IL code in it.

Step 3: Executing the Program

To execute the program from the command prompt, run the exe file which got created as following

eg:  C:\CSharp\Example.exe


eg:  C:\CSharp\Example

Note: to see IL code in .exe file which got created after compilation, we use a special tool called ILDASM


** If you like this post please like our page in facebook "Dot Net Support"  


Post a Comment


Twitter Delicious Facebook Digg Stumbleupon Favorites More