The theme of the new features of C# 4.0 centers on interoperability. The biggest feature in that
respect is the new dynamic type. By using dynamic, the cumbersome rigmarole of interoperating with
COM objects or types created by .NET dynamic languages is a thing of the past. Visual Basic has had a
leg up on C# for quite some time with respect to interoperability. But with C# 4.0, the playing field has
been leveled.
Each time the C# development team embarks on a new feature cycle, they must choose from a list of
feature ideas and requests. For some time, default method argument values has been on that list, but
prior to C# 4.0, has never been implemented. However, interoperability is just the compelling reason
needed to reach the tipping point. With default argument values, interoperating with COM types
becomes even easier. However, there is another feature that goes hand-in-hand with default arguments
values and that is named arguments. In C# 4.0, you can pass arguments to methods as named arguments
such that ordering of arguments in the argument list is irrelevant. As nice as that sounds, it is even more
powerful when you couple it with default argument values and COM interoperability. Often, COM
automation interfaces contain methods with many parameters that are often optional. Using default
arguments, you do not have to provide values for all of them. And by using named arguments, you can
pick and choose which of the arguments in the default list of arguments you want to provide.
Rounding out the new features of C# 4.0 is that of variance. New contextual keyword support was
added to allow one to declare covariant and contravariant generic interfaces and delegates. By
decorating the generic arguments with the in and out keywords, you can declare the interface as co- or
contravariant. This allows such intuitive implicit covariant conversions from IEnumerable
references to IEnumerable