The .net framework is a software framework that runs usually on microsoft windows. It supports several programming languages like vb, c#, jscript, vbscript etc., that provide language interoperability to the framework. It also includes a large library that is available to all the programming languages that .net supports. Programs written for the .net framework execute in software environment, known as Common Language Runtime (CLR).
The execution process of .net framework is as follows:
- First of all, the code written in any language that framework supports is compiled by its appropriate compiler.
- This compiled code is known as IL (Intermediate Language) code, which is also called as managed code.
- The managed code is then passed through common language runtime where it is again compiled and converted to object code (or native code) by JIT (Just In Time) compiler and then passed to the operating system or other hardware.
What is Common Language Runtime?
Common Language Runtime is an application virtual machine that runs the code and provides important services such as security, code execution, memory management, garbage collection and exception handling which makes development process easier.
The class library and CLR together form the .net framework. Common Language Runtime also provides an abstraction layer over the operating system.
The runtime manages the references to objects and automatically handles object layout. It performs memory management by releasing the references to objects when the objects are no longer needed. Such management of objects is called as managed data.
Garbage collection eliminates the memory leaks as well as some other common programming errors. We can use the managed data, unmanaged data, or both in our .NET Framework application, if the code is managed.
The two main components of Common Language Runtime (CLR) are:
- Common Type System (CTS)
- Common Language Specification (CLS)
Common Type System:
Common Type System is a specification for how types are defined, used and managed in runtime. It establishes a framework that helps to provide cross-language integration. It also defines the rules for languages to follow, that help the objects written in different language to interact with each other.
Common type system supports two general categories: value types and reference types. Value types contain the data or value, and are allocated on stack whereas reference types store a reference to the value’s memory address, and are allocated on heap.
CLR provides a set of primitive types that all languages support. The datatypes include:
Integer – three types: 16/32/64 bits
Float – two types: 32/64 bits
Boolean and Character
DateTime and Time Span
Common Language Specification:
Common Language Specification (CLS), is a set of basic language features that are needed by many applications. The rules that apply to common type system, apply to CLS as well, but the rules of CLS are more stricter. CLS ensures interoperability by defining a set of features that developers can depend on and are available in wide variety of languages.
Thus due to Common Type System and Common Language Specification, .net framework supports language interoperability, cross-language integration, language independence, etc.