Search code examples
c#-4.0optional-parametersoptional-arguments

C# 4.0 optional out/ref arguments


Does C# 4.0 allow optional out or ref arguments?


Solution

  • As already mentioned, this is simply not allowed and I think it makes a very good sense. However, to add some more details, here is a quote from the C# 4.0 Specification, section 21.1:

    Formal parameters of constructors, methods, indexers and delegate types can be declared optional:

    fixed-parameter:
        attributesopt parameter-modifieropt type identifier default-argumentopt
    default-argument:
        = expression

    • A fixed-parameter with a default-argument is an optional parameter, whereas a fixed-parameter without a default-argument is a required parameter.
    • A required parameter cannot appear after an optional parameter in a formal-parameter-list.
    • A ref or out parameter cannot have a default-argument.