Saturday, March 23, 2013

Common Language Runtime



 The Common Language Runtime (CLR)

Microsoft's CLR implements the Common Language Infrastructure
  •      Common Type System (CTS) - This defines the rules for defining data types  irrespective of the source language used.
  •      Common Language Specification (CLS) - This is a subset of the CTS. It is a set of types that may be used in external calls in code that is intended to be portable.
  •     Microsoft Intermediate Language (MSIL) - This is the set of machine instructions defined for use with all .NET languages. The Intermediate code is platform independent, but not automatically type safe, as in C++. Also referred to as managed code and managed data.
  •     Metadata - This is information associated with the managed code and data that describes the data, identifies the locations of references to objects, and gives the Virtual Execution System information to handle overhead of older programming models.
  •   J IT Compiler - This converts the MSIL into native code of the operating system.
  •   Garbage Collector (GC) - This manages the memory when the code is running in the VES( Virtual Execution System). Every so often the GC inspects the memory in use by the computer and removes anything that is no longer needed by the .NET application that is running in the VES. This does not mean that code can be written so that the GC tidies everything up, but instead it should be used as an aid to making applications run smoothly.
  •    Virtual Execution System (VES) - This is the part of the system that runs and manages .NET code at runtime in a similar manner to the Java Virtual Machine for the Java Language. The VES sits between the managed code and the native operating system.
At a high level, the CLR is responsible for basic system services such as
  •                      memory management
  •                    threading
  •                      error control
  •                    type safety

. The runtime automatically handles object layout and manages references to objects, releasing them when they are no longer being used, through the use of a Garbage Collector.

Features of  C# 4.0

The main  features in C# 4.0 are:
• Dynamic binding
• Type variance with generic interfaces and delegates
• Optional parameters
• Named arguments
• COM interoperability improvements


Dynamic binding is C# 4.0’s biggest innovation. This feature was inspired by dynamic languages such as Python, Ruby, JavaScript, and Smalltalk.Dynamic binding defers binding—the process of resolving types and members—from compile time to runtime. Although C# remains a predominantly statically typed language, a variable of type dynamic is resolved in a late-bound manner. 
For example:
dynamic d = "hello";
Console.WriteLine (d.ToUpper()); // HELLO
Console.WriteLine (d.Foo()); // Compiles OK but gives runtime error


Calling an object dynamically is useful in scenarios that would otherwise require complicated reflection code. Dynamic binding is also useful when interoperating with dynamic languages and COM components.
Optional parameters allow functions to specify default parameter values  so that callers can omit arguments. An optional parameter declaration such as:
void Foo (int x = 23) { Console.WriteLine (x); }
can be called as follows:
Foo(); // 23
Named arguments allow a function caller to identify an argument by name rather than position. For example, the preceding method can now be called as follows:
Foo (x:5);
Type variance allows generic interfaces and generic delegates to mark their type parameters as covariant or contravariant. This enables code such as the following to work:
IEnumerable<string> x = ...;
IEnumerable<object> y = x;
COM interoperability  has been enhanced in C# 4.0 in three ways. First,
arguments can be passed by reference without the ref keyword. This feature is particularly
useful in conjunction with optional parameters


0 comments:

Post a Comment