Since C# added optional parameters is it considered a better practice to use optional parameters or method overloads or is there a particular case where you would want to use one over the other. i.e a function w/ lots of parameters would be better suited w/ optional parameters?
Since C# added optional parameters is it considered a better practice to use optional
Share
Optional parameters are nice, but should be used when it makes sense. Optional parameters often muddy the intent of the method — If there is another alternative I would lean towards the alternative.
Part of the need for optional parameters and named parameters is because COM allowed optional and name parameters:
MSDN
SomeNewKid from forums.asp.net puts succinctly:
http://forums.asp.net/t/386604.aspx/1
Keep in mind that optional parameters are a syntactical sugar:
Reflector C#:
IL: