Well after years of maintaining a pure statically type checked face, the C# team is relenting a bit on this stance. In C# 4.0 you will be able to write code that uses late binding in a much easier way. Note that VB has had this capability since it shipped. What this means it the C# gets one new keyword “dynamic” which actually carries static type information (ie just that the associated variable uses runtime binding) and that type information flows throughout your program as you dynamic variables in other places.
Also, in order to make Office (COM OM) programming easier from C#, they have added support for optional and named parameters. This makes using certain Office methods that take say 30+ parameters, most of them optional, much easier to invoke from C# 4. Here’s what these features look like from a very simple usage:
Note that when you run this program and hit line 9, you get this error:
Here’s the IL for the code above:
The one thing here I really don’t like is that it appears the “optional” value is being embedded at the call-site (see line 11 above). This has versioning issues. I hope I’m wrong about this or the C# team changes this behavior before shipping. Note that on line 4 you can see the call-site caching that happens for dynamic invocation. This means that the first dynamic call to this method will be expensive but future invocations (say if this code was called a lot) will be much faster.