Home > Articles > Programming > C#

  • Print
  • + Share This
Like this article? We recommend

Like this article? We recommend

Compiling and Testing Your C# Program

To compile a C# source file, you type csc filename in the DOS window. Our program is named test.cs, so the steps are pretty easy:

  1. Type csc test.cs and press Enter (see the selected section of Figure 44).

    If you haven't made any errors and you've installed the SDK correctly, the compiler should simply display its name, version number, and some copyright information (see the selected section of Figure 45).

    Figure 44 Starting the C# compiler.

    Figure 45 Display if no errors.

  2. If you have error messages after the copyright notice, reopen the test.cs file in Notepad (type notepad test.cs and press Enter), and make sure that the code looks exactly as shown earlier in Figure 43. For example, suppose you got this error message:

    'csc' is not recognized as an internal or external command,
    operable program or batch file

    You probably didn't set the PATH variable correctly (refer to the earlier section "Setting the PATH Environment Variable").

  3. Once the code is compiling correctly, you're ready to run your program. To run the program, you simply type its base name (test in this example). Type test and press Enter (see Figure 46). Your program should display Flotation is Groovy! (see Figure 47).

    Figure 46 Executing the test program.

    Figure 47 Program output (selected).

That's it! With the development environment working, in the next article, we can focus on learning more of the C# language and do far more complex examples. We can also start grounding some of the .NET concepts, changing them from floating abstractions to useful, related knowledge.

  • + Share This
  • 🔖 Save To Your Account