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.csIf 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
HelloThis 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 filethen it means that you must help the command window locate the C# compiler, csc. Here's how:
You will probably locate the program in a folder named something like
c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727This folder is the ``path'' to the compiler.
set path=c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727Now, you can cd to the folder that contains your C# program and type csc Hello.cs
;c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
pathYou 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
cscand 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.