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.
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
Latest posts by Lalit Mali (see all)
- Rank Pages in a Directory by Occurrence of a Particular Word in them – Java Data Mining - October 16, 2012
- Java Data Mining: Number of occurrences of a word in a file - October 15, 2012
- Calculate factorial of a number using C++ Recursive function - October 14, 2012