C#.NET 4.0

Introduction:
  • C# is pronounced as C Sharp.
  • C# is a simple, general-purpose, object-oriented programming language.
  • C# is a case sensitive language.
  • Every statement ends semi colon.
The new features in C# 4.0 are: 
  • Dynamic binding   
  • Type variance with generic interfaces and delegates   
  • Optional parameters    
  • Named arguments   
  • COM interoperability improvements
Dynamic Binding:
Dynamic binding  is C# 4.0’s biggest innovation. It 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.Do()); // 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.
Type variance:
Type variance  allows generic interfaces and generic delegates to mark their type parameters as covariant or contravariant.

Optional parameters:
Optional parameters allow functions to specify default parameter values so that callers can omit arguments. An optional parameter declaration is as follows
          void Do (int x = 50) 
         {
            Console.WriteLine (x); 
          }
           can be called as follows:
           Do(); // 50

Named arguments:
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:
Do(x:5);

COM interoperability:
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 particularlyuseful in conjunction with optional parameters.
  • Second, assemblies that contain COM interop types can now be linked rather than referenced. Linked interop types support type equivalence, avoiding the need for Primary Interop Assemblies and putting an end to versioning and deployment headaches.
  • Third, functions that return variant types from linked interop types are mapped todynamic rather than object, eliminating the need for casting.

Click Here  : C#.NET Language Basics

No comments:

Post a Comment