Decorating parameters with the OptionalAttribute parameter also does not work. To expand on the previous sample, you will get something like:
private void Func( [Optional] out int optional1, [Optional] out string optional2) { }
Please note that the above will compile (maybe unfortunately). However, trying to compile:
Func(out i);
will fail if an overload with a one-parameter signature is not explicitly specified.
To (theoretically) makes the above work a serious problem. When a method is called with an optional parameter omitted, a stack frame is created containing the values ββof all parameters, and the missing values ββare simply filled with the specified default values.
However, the out parameter is a reference, not a value. If this parameter is optional and not specified, which variable does it reference? The compiler still needs to fulfill the requirement that the "out" parameter be filled before any normal return from the method, since the compiler does not know a priori what additional parameters are specified by the caller (if any). This means that it would be necessary to refer to the dummy variable somewhere, so the method must fill something. Managing this dummy variable space would create an unpleasant headache for the compiler writer. I'm not saying that it would be impossible to make out the details of how this will work, but the architectural implications are great enough for Microsoft to convey this function in an understandable way.
John Beyer Mar 13 '12 at 19:29 2012-03-13 19:29
source share