If you’re not aware of the Optional or Named Parameters feature introduced in C# 4.0, take a look at this video before reading this article:
http://msdn.microsoft.com/en-us/vcsharp/ee460905.aspx
The Good:
1) This features will certainly help you reduce the number of overloads for your methods.
2) The calls to the methods will be more reader friendly.
Eg. SetUserName(lastName: “Hello”, firstName: “World”); // the user will know which value goes into which parameter without having to look up the method signature.
3) Calls to a lot of COM APIs will now be simpler
The Bad:
1) When you compile a code that calls a method using named parameters, the parameter name used in the call is stored at callsite (i.e. in the assembly where the method is being called). If the method is actually defined in a different assembly (say a library dll that your other projects use), then this can have unindented side effects. Lets say you change one of the parameter names in your method and compiled your library dll and deployed it without compiling the other projects that use it. If the order and type of your parameters hasn’t changed you could still get by, cos the caller simply calls the methods as they did in earlier versions of C#. The named parameter call is only for the benefit of the reader. However, if the type or order of the parameters have changed the you are in trouble. You’ll have to recompile all the projects that use your library to reflect this change.
2) Another, and more serious side effect would be when you are using optional parameters. The values of optional parameters are also stored on the callsite. Hence if you change the default value of any parameter in your library dll and deploy it without recompiling the projects that use it, then your method will continue to get the old default values! This could lead to some bugs.
The Learning:
Although this new feature is pretty useful, developers should be aware of these side effects. Think of parameter names and the default values as a part of your public interface, just like the name of your method. That will make you think hard before changing parameter names or default values.



