Locating and using the C# compiler

Say that you typed a C# program, and you wish to execute it. First, you must compile the program (check spelling, grammar, data types, and translate into an exe-file). Do this by opening a command window, opening the folder that holds Hello.cs, and typing at the command line,

csc Hello.cs
If you make a spelling or punctuation error, you will be informed; read the error message, note the line and character where the error appears, correct it, and compile again. If the program is properly spelled, then you will receive a prompt, and a file, Hello.exe, will be constructed in the same folder where Hello.cs lives. You type next
Hello
This executes the program.

If you type csc Hello.cs in the command window, and you see

'csc' is not recognized as an internal or external command,
operable program or batch file
then it means that you must help the command window locate the C# compiler, csc. Here's how:
  1. First, locate the C# compiler on your computer. (You can use your computer's search facility: press Start in the lower left corner, press Search, then within the Search window, select ``Search all files'' and then type a search for csc.exe.)

    You will probably locate the program in a folder named something like

    c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
    
    This folder is the ``path'' to the compiler.
  2. Next, you must tell the command window the path to the compiler. The simplest way to do this is to open a new command window and type this command:
    set path=c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
    
    Now, you can cd to the folder that contains your C# program and type csc Hello.cs
  3. It is a nuisance to type the set path command each time you open a command window, and if you prefer to set the path permanently, then This permanently adds the path to the C# compiler to the paths used by the command window. To confirm you did this correctly, open a command window and type
    path
    
    You will see the list of folders (paths) that the command window searches when you ask it to execute a program (like notepad or csc). The last folder in the list should be the path to the C# compiler that you just added. You can also check by typing just
    csc
    
    and you will get a message from the C# compiler.

In addition, your computer might already have an IDE (Integrated Development Environment) for C# (e.g., Visual Studio). To find out if you do, open a file window and locate the icon for Hello.cs. Double-click on it. If a complex IDE window appears, and your program appears in the IDE's window, then you can compile and execute the program by clicking on the buttons or menu items of the IDE --- Look for a button named Compile or Build to compile the program. Then, look for a button named Execute.