Of fundamental importance to the .NET framework is the fact that programs are executed within a managed execution environment provided by the Common Language Runtime. The CLR greatly improves runtime interactivity between programs, portability, security, development simplicity, cross-language integration, and provides an excellent foundation for a rich set of class libraries.
Absolutely key to these benefits is the way .NET programs are compiled. Each language targeting .NET compiles source code into metadata and Microsoft Intermediate Language (MSIL) code. Metadata includes a complete specification for a program including all its types, apart from the actual implementation of each function. These implementations are stored as MSIL, which is machine-independent code that describes the instructions of a program. The CLR uses this “blueprint” to bring a .NET program to life at runtime, providing services far beyond what is possible with the traditional approach—compiling code directly to assembly language.
Key features of the CLR include the following:
Programs can be run without recompiling on any operating system and processor combination that supports the CLR. A key element of this platform independence is the runtime’s JIT ( Just-In-Time Compiler), which compiles the MSIL code it is fed to native code that runs on the underlying platform.
The Common Type System (CTS) of the CLR defines the types that can be expressed in metadata and MSIL and the possible operations that can be performed on those types. The CTS is broad enough to support many different languages, including Microsoft languages, such as C#, VB.NET, and VC.NET, and such third party languages as COBOL, Eiffel, Haskell, Mercury, ML, Oberon, Perl, Python, Smalltalk, and Scheme.
The Common Language Specification (CLS) defines a subset of the CTS, which provides a common standard that enables .NET languages to share and extend each other’s libraries. For instance, an Eiffel programmer can create a class that derives from a C# class and override its virtual methods.
The CLR provides interoperation with the vast base of existing software written in COM and C. .NET types can be exposed as COM types, and COM types can be imported as .NET types. In addition, the CLR provides PInvoke, which is a mechanism that enables C functions, structs, and callbacks to be easily used from within in a .NET program.