Work with C# in Command prompt


Do you want to install and run C# (C Sharp) from your command prompt? Then this post is for you.

Well, chances are that you probably already have everything already installed and ready on your computer.

Step 1: Installing .Net Framework on your computer.

To check whether you already have this on your computer, navigate to this folder ‘C:\Windows\Microsoft.NET\Framework\

You might be having folders with names like ‘v2.0.xx‘, ‘v3.0‘, etc.

If you do have such folders but want to make sure you have the latest version installed then continue with this step. If you’re happy with what you have, jump to Step 2.

For those who do not have such folders,

Go install the .Net Framework 4.0, which is the current(Nov 2011) latest stable release. If you are reading this at a later date you can search for a newer 1 if available.


Step 2: Setting up the path for the compiler.

Copy the path to your compiler

Navigate to the folder ‘C:\Windows\Microsoft.NET\Framework\’ again and open the folder for the latest version avaiable in your computer. eg. ‘v4.0.30319

Now copy the path to this  folder from the address bar at the top. it will be something like ‘C:\Windows\Microsoft.NET\Framework\v4.0.30319

Set-up path variable

Right-click on MyComputer->Properties->Advanced System Settings

In the new dialog that will open, go to ‘Advanced‘ tab and click on ‘Environment variables

Click on ‘New…‘  in the upper half of the screen and enter these values:

Variable Name: path
Variable value: <paste the path you copied before>

Congrats, your computer is now ready to compile and run C# programs.



You should consider installing a different kind of text editor (a source code editor) for writing your programs.

Notepad++ and ConTEXT are 2 very good source code editors. You can either use these or find others by searching on the internet.

These editors have advantages like Syntax Highlighting and Auto-Indentation to name a few. Also, other than C#,  they support many programming languages like C/C++, Java, VB, HTML, PHP, CSS, etc.


How to compile and run?

Save your C# file as AnyFileName.cs to any folder of your choice and copy the path to it.
eg. ‘C:\Learning\C sharp programs\

Then open up a command prompt window: Start->search for cmd or Start->Run->cmd

Change the directory to the folder where your C# file is saved by typing ‘cd <path to your C# file>’
eg. ‘cd C:\Learning\C sharp programs\

Compile your program:
Type ‘csc AnyfileName.cs

Run your program:

Just type ‘AnyfileName.exe

Anything not working the way mentioned here? Let us know in Comments. Enjoy Programming :)

The following two tabs change content below.

Lalit Mali

Lalit is a technology enthusiast, a programming lover and currently an Android fan.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">