Datasheet

How Do I Write Applications Using the .NET Framework?
Writing an application using the .NET Framework means writing code (using any of the languages that
support the Framework) using the .NET code library. In this book you use VS for your development
VS is a powerful, integrated development environment that supports C# (as well as managed and
unmanaged C++, Visual Basic, and some others). The advantage of this environment is the ease with
which .NET features can be integrated into your code. The code that you will create will be entirely C#
but will use the .NET Framework throughout, and you make use of the additional tools in VS where
necessary.
In order for C# code to execute, it must be converted into a language that the target operating system
understands, known as native code. This conversion is called compiling code, an act that is performed by
a compiler. Under the .NET Framework, however, this is a two-stage process.
MSIL and JIT
When you compile code that uses the .NET Framework library, you don’t immediately create operating
system–specific native code. Instead, you compile your code into Microsoft Intermediate Language (MSIL)
code. This code isn’t specific to any operating system and isn’t specific to C#. Other .NET languages
for example, Visual Basic .NET also compile to this language as a first stage. This compilation step is
carried out by VS when you use it to develop C# applications.
Obviously, to execute an application more work is necessary. This is the job of a Just-in-Time (JIT) com-
piler, which compiles MSIL into native code that is specific to the OS and machine architecture being
targeted. Only at this point can the OS execute the application. The just-in-time part of the name here
reflects the fact that MSIL code is only compiled as and when it is needed.
In the past, it was often necessary to compile your code into several applications, each of which targeted
a specific operating system and CPU architecture. Often, this was a form of optimization (to get code to
run faster on an AMD chipset, for example), but at times it was critical (for applications to work in both
Win9x and WinNT/2000 environments, for example). This is now unnecessary, because JIT compilers (as
their name suggests) use MSIL code, which is independent of the machine, operating system, and CPU.
Several JIT compilers exist, each targeting a different architecture, and the appropriate one will be used
to create the native code required.
The beauty of all this is that it requires a lot less work on your part in fact, you can just forget about
system-dependent details and concentrate on the more interesting functionality of your code.
Assemblies
When you compile an application, the MSIL code created is stored in an assembly. Assemblies include
both executable application files that you can run directly from Windows without the need for any other
programs (these have a
.exe file extension), and libraries for use by other applications (which have a
.dll extension).
As well as containing MSIL, assemblies also contain meta information (that is, information about the
information contained in the assembly, also known as metadata) and optional resources (additional data
used by the MSIL, such as sound files and pictures). The meta information allows assemblies to be fully
5
Introducing C#
05_578472 ch01.qxd 9/22/05 10:54 PM Page 5