30-04-2012, 01:03 PM
The Relationship of C# to .NET
CSharpI.doc (Size: 873 KB / Downloads: 47)
The Common Language Runtime
• Central to the .NET framework is its run-time 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 we develop needs to be compiled. Compilation occurs in two steps in .NET:
1. Compilation of source code to Microsoft Intermediate Language (MS-IL)
2. Compilation of IL to platform-specific code by the CLR
Advantages of Managed Code
Platform Independence
Language Interoperability
COM and COM+ Interoperability
Intermediate Language
Here are the important features of the Intermediate Language:
• Object-orientation and use of interfaces
• Strong distinction between value and reference types
• Strong data typing
• Error handling through the use of exceptions
• Use of attributes
Common Type System (CTS)
• This data type problem is solved in .NET through the use of the Common Type System (CTS).
• The CTS defines the predefined data types that are available in IL, so that all languages that target the .NET framework will produce compiled code that is ultimately based on these types.
Common Language Specification (CLS)
• The Common Language Specification works with the Common Type System to ensure language interoperability.
• The CLS is a set of minimum standards that all compilers targeting .NET must support.
• Since IL is a very rich language, writers of most compilers will prefer to restrict the capabilities of a given compiler to only support a subset of the facilities offered by IL and the CTS.
• That is fine, as long as the compiler supports everything that is defined in the CLS
• It is perfectly acceptable to write non-CLS-compliant code. However, if you do, the compiled IL code isn't guaranteed to be fully language-interoperable.
Garbage Collection
The garbage collector is .NET's answer to memory management, and in particular to the question of what to do about reclaiming memory that running applications ask for.
Up until now there have been two techniques used on Windows platform for deallocating memory
• Make the application code do it all manually
• Make objects maintain reference counts
The .NET runtime relies on the garbage collector instead.
This is a program whose purpose is to clean up memory.