2.2. Writing Your First C# Program

We assume here that you have successfully downloaded and installed the bare bones .NET SDK on your C: drive. To compile your C# programs, you need the compiler, which is a file called csc.exe. By default, the compiler converts C# code to a shell executable file that can be run like any EXE file. Think of this EXE file as the Java runtime, with all the classes to be run put in one file. To compile your code from anywhere, you must set the directory so that the csc.exe file is in your system PATH environment variable. You can check this by typing csc at the command prompt, as shown in Listing 2.1. Note that fatal error CS2008 is really reminding you that the compiler has no files to compile.

Listing 2.1. Output ...

Get .NET for Java Developers: Migrating to C# now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.