Sams Teach Yourself C in 21 Days

(singke) #1
With C#, you use a compiler that does not produce machine language. Instead it pro-
duces an Intermediate Language (IL) file. Because this isn’t directly executable by the
computer, you need something more to happen to translate or further compile the pro-
gram for the computer. The CLR or a compatible C# runtime does this final compile just
as it is needed.
One of the first things the CLR does with an IL file is a final compile of the program. In
this process, the CLR converts the code from the portable, IL code to a language
(machine language) that the computer can understand and run. The CLR actually com-
piles only the parts of the program that are being used. This saves time. Additionally,
after a portion of your IL file has been given a true compile on a machine, it never needs
to be compiled again, because the final compiled portion of the program is saved and
used the next time that portion of the program is executed.

772 Bonus Day 7

Because the runtime needs to compile the IL file, it takes a little more time
to run a program the first time than it does to run a fully compiled lan-
guage such as C++. After the first time a program is completely executed,
the time difference disappears because the fully compiled version will be
used from that point. You also have the ability to have this compilation
done when you install the program.

Note


The last minute compiling of a C# program is called Just In Time compiling or
jitting.

Compiling C# Source Code

To create the IL file, you use the C# compiler. You typically use the csccommand to run
the compiler, followed by the name of the source file. For example, to compile a source
file called radius.cs, you type the following at the command line:
csc radius.cs
If you’re using a graphical development environment, compiling is even simpler. In
most graphical environments, you can compile a program by selecting the compile icon
or selecting the appropriate option from the menu. After the code is compiled, selecting
the run icon or selecting the appropriate option from the menus executes the program.
You should check your compiler’s manuals for specifics on compiling and running a pro-
gram.

NEWTERM

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

Free download pdf