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
2009-03-20 01:31:56
FIXME: Who is Sam Ng? Is he a M$ developer?
strager
2009-03-20 01:37:38
I think that all the bloggers on blogs.msdn.com are MS employees (maybe some are MVPs?).
Michael Burr
2009-03-20 01:45:03
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
2009-04-24 09:46:19
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
2010-07-04 10:11:40