Skip to main content

Posts

Showing posts from August, 2013

Optional Parameters in C#

C# 4.0 has a nice feature of creating methods with optional parameters which allows caller to pass only required parameters and not all. This is particular helpful in methods which needs a lot of parameters. Method with optional parameters : Out put :15 Here caller is only passing one parameter i.e. 5 and output is 15 because default value for parameter b is used which is 3. but, care should be taken when you create methods with optional parameters in a library which is used by third party application (where you have less control) because by just changing the default value in the library , if this new library is deployed (with every thing as it is),  client apps will NOT see the change. Client application also needs to be re-compiled with the updated library to see the changes because of the new default value.  in the above example , if OptionalParam.exe uses   updated library.dll (without recompiling the complete solution ) where default value of b has been changed from