Friday, December 31, 2010

C Sharp 4.0 New Features


.NET Framework 4.0
The Microsoft was released the first version of the .NET Framework 1.0 in 2002 to much enthusiasm. The major release of the .NET Framework 2.0 was introduced in 2005. The another major release of the .NET Framework 4.0 is a product with many outstanding new features
Sharp 4.0 New Features
  • Dynamic Typing
  • Optional and Named Parameters
  • Improved COM-Interop
  • Contra and Co-Variance
Dynamic Typing
The Microsoft has released a new dynamic typing capability in C Sharp. It is now always possible to know statically what objects might end up being. Instead of using the object keyword and making everything of this type, we can now let the DLR out at runtime. 
You are able to Interop with various dynamic languages and work with DOM more easily. It is even simple to work with the Microsoft Office COM APIs now.
The DLR has been built upon the Common Language Runtime to provide the ability to together all the dynamic language interactions. 
The new "dynamic" keyword use to access the new DLR, this flag to the compiler; when this keyword is encountered, the compiler will realize that it is a dynamic invocation and not the typical static invocation.
Optional and Named Parameters
Optional parameters allow you to provide default values for some of the parameters of your methods and allow for a type of overloading by the consumer, even if there is only a single method in place to deal with all the variants.
Class UserSettings
{
   public void NewUser(string firstName, string lastName, bool isAdmin, bool isUser)
  {
  }

}
If you want to overload this and have default values for the two bool objects, then you could easily have a few more methods that populate these values for the consumer and then make a call to the master method to actually create the New User. 
Optional parameters 
public void NewUser(string firstName, string lastName, bool isAdmin=false, bool isUser=true)
{
}

The parameters firstName and lastName do not have a default value. But the another parameters do have default value.

myuser.NewUser("C Sharp", "Tutorial");
myuser.NewUser("C Sharp", "Tutorial", true);
myuser.NewUser("C Sharp", "Tutorial", true, false);
myuser.NewUser("C Sharp", "Tutorial",  isUser: false);
Contra and Co-Variance
The prior version of .NET, you were able to use contra-variance with objects and arrays, but for instance, you were unable to use contra-variance with generic interface.  
In. NET 4.0 to extend to perform even better when working with generics and delegates.

0 comments:

Post a Comment

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Best Wallpapers collections