Datasheet
The Relationship of C# to .NET
C# is a relatively new programming language and is significant in two respects:
❑ It is specifically designed and targeted for use with Microsoft’s .NET Framework (a feature-rich
platform for the development, deployment, and execution of distributed applications).
❑ It is a language based on the modern object-oriented design methodology, and when designing
it Microsoft learned from the experience of all the other similar languages that have been
around since object-oriented principles came to prominence some 20 years ago.
One important thing to make clear is that C# is a language in its own right. Although it is designed to
generate code that targets the .NET environment, it is not itself part of .NET. Some features are supported
by .NET but not by C#, and you might be surprised to learn that some features of the C# language are
not supported by .NET (for example, some instances of operator overloading)!
However, because the C# language is intended for use with .NET, it is important for you to have an
understanding of this Framework if you want to develop applications in C# effectively. So, this chapter
takes some time to peek underneath the surface of .NET. Let’s get started.
The Common Language Runtime
Central to the .NET Framework is its runtime execution environment, known as the Common
Language Runtime (CLR) or the .NET runtime. Code running under the control of the CLR is often
termed managed code.
However, before it can be executed by the CLR, any source code that you develop (in C# or some other
language) needs to be compiled. Compilation occurs in two steps in .NET:
1. Compilation of source code to IL
2. Compilation of IL to platform-specific code by the CLR
This two-stage compilation process is very important, because the existence of the IL (managed code) is
the key to providing many of the benefits of .NET.
Advantages of Managed Code
Microsoft Intermediate Language shares with Java byte code the idea that it is a low-level language with
a simple syntax (based on numeric codes rather than text), which can be very quickly translated into
native machine code. Having this well-defined universal syntax for code has significant advantages.
Platform Independence
First, it means that the same file containing byte code instructions can be placed on any platform; at run-
time the final stage of compilation can then be easily accomplished so that the code will run on that par-
ticular platform. In other words, by compiling to IL you obtain platform independence for .NET, in
much the same way as compiling to Java byte code gives Java platform independence.
4
Part I: The C# Language
24727c01.qxd:WroxPro 5/7/07 12:12 PM Page 4