Comments on: C# 4 Optional Parameters Limits Default Value http://jrwren.wrenfam.com/blog/2010/07/04/c-4-optional-parameters-limits-default-value/ babblings of a computer loving fool Mon, 21 Nov 2016 19:37:12 +0000 hourly 1 https://wordpress.org/?v=4.7.2 By: Jon Skeet http://jrwren.wrenfam.com/blog/2010/07/04/c-4-optional-parameters-limits-default-value/comment-page-1/#comment-31444 Mon, 05 Jul 2010 06:08:52 +0000 http://jrwren.wrenfam.com/blog/2010/07/04/c-4-optional-parameters-limits-default-value/#comment-31444 Yes, it’s definitely another use for the Option idea… but I’m not surprised it doesn’t work at the moment. Basically you would need to overhaul the way that default values work in .NET in general – although I believe it would be feasible to support both approaches at the same time. The current system is all about telling the caller what the default is, so that the compiler can bake it in. My suggestion would be for the caller to effectively only say “Here’s a value” or “please use the default.”

]]>
By: zproxy http://jrwren.wrenfam.com/blog/2010/07/04/c-4-optional-parameters-limits-default-value/comment-page-1/#comment-31443 Mon, 05 Jul 2010 05:32:17 +0000 http://jrwren.wrenfam.com/blog/2010/07/04/c-4-optional-parameters-limits-default-value/#comment-31443 Jay, the compiler would be calling that implicit operator on the call site.

class Things { public Things(Default a = 5) { } }

is compiled to

class Things { public Things([Optional] Default a) { } }

and callable as

new Things(Default.op_implicit(5));

]]>