views:

958

answers:

2

Is C# 4 optional parameter implementation the same as VB.NET, the optional parameter is compiled on the call site(can cause versioning problems)?

+3  A: 

According to SamNg, C#'s default arguments are is compiled at the call site, similar to default parameters in C++.

Yes, it would cause versioning problems. However, optional parameters should be used where it makes sense. In many cases, this means passing null or default-constructed class to a method or constructor.

strager
FIXME: Who is Sam Ng? Is he a M$ developer?
strager
I think that all the bloggers on blogs.msdn.com are MS employees (maybe some are MVPs?).
Michael Burr
+4  A: 

Yes.

Mitch Wheat
This adds a serious weakness to C#. The fact that optional is implemented at the call site rather than as an overload means that assemblies that aren't built against each other will not work if an optional parmaeter is changed. I don't see why we need it. Overloading gives the same functionality and method signatures are never modified invisibly.
Stevo3000
The default value is part of the function's definition. Changing it is just as bad as changing the name of the function. This is just as true when the default is baked into an overload as when it is exposed via a optional parameter.
Jonathan Allen