Some answers seem to have some misinformation:
- More options were introduced in C # 4, so you should use the C # 4 compiler
- The optional parameters were in the structure forever, so you can target any version of the framework and use them as long as you use the C # 4 compiler. It is advisable to target .NET 2 to the C # 4 compiler, and then someone refers to your a library, for example, VB8 will still be able to use your optional parameters.
As others noted, overloads are an alternative to using optional parameters if you are not using C # 4 or want your code to be used by earlier C # code. (If you are creating a library using C # 4, but then you need to call the C # 3 code, these optional parameters will really be needed for this code.)
(Aside, I would seriously review your names ... I know that this is just a code example, but in general, prefixes such as "p" for parameters are discouraged as conditional, and similar methods are usually Pascal-cased.)
source share