Thursday, November 6, 2008

Optional Parameters (C#)

“Yes”! This was the word out of my mouth when reading about the new C# 4.0 that will be coming soon. Why? Well, a couple of months ago I wrote a post about optional parameters in VB.NET and how useful they can be. I also questioned why the C# team didn’t implement this feature. My answer is here (quoting a white paper from the C# team):

Named and optional parameters
“Parameters in C# can now be specified as optional by providing a default value for them in a member declaration. When the member is invoked, optional arguments can be omitted. Furthermore, any argument can be passed by parameter name instead of position.”

And the same white paper goes on justifying this new feature much the way I did on my blog post:

COM specific interop features
“Dynamic lookup as well as named and optional parameters both help making programming against COM less painful than today. On top of that, however, we are adding a number of other small features that further improve the interop experience.”

They’ve taken the “optional parameter” idea even further and introduced Named Parameters.
Day after day, the .NET world keeps on surprising me.