One of the things I missed most, when moving from PHP to C#, was the way PHP let you pass along default parameters for any function. Now it look like C# 4.0 gets the same feature. Now I often find myself writing lots of overloaded methods, just because I want it to be easier to use the methods later on in the project
So this is how it is done today:
However, with the new feature in C#4.0, you can now put default values directly into the method:
That little line of code, covers all of the methods I wrote with C#3.5. The only thing to note, is that when you use similar input types for the parameters, it always used the first default values it finds. In the next example, using “foo(“s string”, false,10)” will set b = false, since it’s the first of 2 boolean default values.
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.