
Visual Studio 2010 is out and we have a new version of C# that also accompanies it. That's C# 4.0 - I have been working on C# from the good old 1.0 or 1.1 version upwards. So whats the new 4.0 version of C# got in store for you. Here's a wrap up of the new features available as part of C# 4.0 release.
keyword Dynamic
There's a new kid in the block, with the introduction of a very a key feature of this release called the dynamic keyword. The keyword dynamic bridges the gap that existed between a dynamically and statically - typed languages. Well, C# can now also be considered a dynamically typed language too. You can easily create dynamic objects on the fly and even have their types determined only at run time. You will simply need to add a new namespace called System.Dynamic, and lo you can create expandable objects and even advanced class wrappers. You can also facilitate interoperability between different languages, including the dynamic ones.
To better understand the use of dynamic keyword, here's an example:
dynamic BankAccount = new ExpandoObject();BankAccount.Number = "174258733-451269";BankAccount.HolderName = "Jason S";BankAccount.Branch = "Bangalore";Though there are many pros and cons for the use of dynamic keyword and the system performance overheads, it makes like that much more simpler for the developer in the end.
Optional (or Default) Method Parameters
If I rightly remember, VB.net is preferred to C# when porting old projects in ancient langues of VB 5 / 6 or when working on creating COM wrappers since VB.net allows you the use of Optional or Default parameters in methods. C# 4.0 has finally got this feature to make it that much more robust in this area.
You can now easily specify a default value for a parameter within the method declaration in C# 4.0. Also, the consumer of the method can either pass a value or can easily skip the parameter. When the parameter is skipped, the default value declared in the method is passed.
Here's a simple example to explain it:
Method declaration:
public static void GetMoney(int amount = 0) { }Bot the below Method calls for the above declaration are valid in C# 4.0:
GetMoney(); // 0 is used as amount in the method.GetMoney(1000);Named Arguments
Well, here's another relief to the developer. Did you know that in C# 4.0 the order of parameters in a method declaration and also the order of arguments you pass to the method when calling don’t need to match anymore!!. You can now easily provide arguments to a method in any order that you are comfortable with by specifying parameter names with-in the method call. This feature also tremendously improves the readability of one's code.
Here's a simple example of using Named Arguments in C# 4.0
var sample = new List(); sample.InsertRange(collection: new List(), index: 0); sample.InsertRange(index: 0, collection: new List()); // both ways it'll work now Covariance and Contravariance
Does the heading sound confusing? Well, the use of variance on generic type parameters in interfaces and delegates is yet another new feature available in C# 4.0. Though, strictly speaking it doesn’t add that much of a new functionality. But it rather makes things work in the first place as you expected them to work. Here is a major advantage that is hidden in the power of C# 4.0 in simple line below. Note: The below code wouldn't have compiled up until C# 4.0 was released:
IEnumerableNow you have the ability to implicitly convert references for objects instantiated with different type arguments. This makes it that much more simpler and easier to reuse code.
Improved COM Interop Support
As I started this article with the dynamic keyword, then we had the optional parameters and named arguments, did you know that all of this actually enables a significant improvement in working with COM interop. Though all these features have arrived pretty late for the COM Interop world - but it's like late than never is better.
Take a look at my ugly code below:
var excelApp = new Excel.Application();// . . .excelApp.get_Range("A1", "B4").AutoFormat( Excel.XlRangeAutoFormat.xlRangeAutoFormatTable3, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);I can now simply write it in a few lines as below:
excelApp.Range["A1", "B3"].AutoFormat( Excel.XlRangeAutoFormat.xlRangeAutoFormatClassic2);Ain't it pretty neat?
So, there you go - that was a wrap up of the new features that are available in C# 4.0. Hope it helped!!





Hard Rock Cafe is all set to open India's fifth Hard Rock Cafe at Hyderabad, which perfectly augements the flagship Mumbai cafe(September 2006) and also locations in Bengaluru(December 2007), Pune(January 2009) and New Delhi(June 2009). The new Hard Rock Cafe Hyderabad is as expected going to be situated near luxury hotels and shopping areas that offer a convenient destination for both local fans and also international travelers.
Hard Rock Cafe Hyderabad like the other destinations will be adorned with pieces from Hard Rock's world-famous memorabilia collection which includes items representing both contemporary stars as well as rock legends, such as Elvis Presley, Elton John, Kylie Minogue and many more. Key memorabilia items on display at Hard Rock Cafe Hyderabad will include a pair of Alain Mikli glasses with gold-colored plastic frames worn by Elton John, a black satin top hat worn by The Beatles' George Harrison during the recording of "Crackerbox Palace," and a leather suede tunic jacket worn by The Who's Roger Daltry in the 70's. Now that's something to watch out for!!



Online meetings are inarguably the most price-less tool for saving people's time and money in a very aggressive and competitive business environments that we see today. But did you know that most online meetings tend to have a sour experience in the host as well as the presenter's minds mainly due to poor training or unpreparedness of both - either the presenter or the host.





