Sams Teach Yourself C in 21 Days

(singke) #1
The C# Programming Language 773

BD7


After you compile, you have an IL file. If you look at a list of the files in the
directory or folder in which you compiled, you should find a new file that has
the same name as your source file, but with an .exe (rather than a .cs) extension. The file
with the .exe extension is your “compiled” program (called an assembly). This program
is ready to run on the CLR. The assembly file contains all the information that the com-
mon runtime needs to know to execute the program.
After your program is a compiled IL file, you can run it by entering its name at the com-
mand-line prompt or just as you would run any other program. The program will not run,
however, unless you have the Microsoft .NET Runtime installed. If you don’t have the
runtime installed you will get errors.

The C# Compiler and the .NET Runtime

Before compiling your C# programs, you’ll need to get a copy of a C# compiler. You
also learned in the previous section that you need a .NET Runtime. The Microsoft .NET
Framework includes a runtime as well as a C# compiler. At the time of this book’s writ-
ing, the .NET Framework could be downloaded free from the Microsoft Web site.

Your First C# Program

Listing B7.1 illustrates a simple C# program. This demonstration uses a program named
hello.cs, which does nothing more than display the words Hello, World!On the screen.
This program is the traditional program used to introduce people to programming. It is
also a good one for you to use to learn.

LISTING1.1 hello.cs. A simple C# program
1: class Hello
2: {
3: public static void Main()
4: {
5: System.Console.WriteLine(“Hello, World!”);
6: }
7: }

As you can see in line 1, C# programs are enclosed in a class. This keeps in line with
being an object-oriented language. You can also see that like C and the other languages, a
Main()method is used as the primary entry point to a program. One difference from C is
the fact that the Main()method starts with a capital letter instead of a lower case letter.
Like C, C# is case-sensitive, so this is an important distinction.

NEWTERM

42 448201x-Bonus7 8/13/02 11:24 AM Page 773

Free download pdf