C#4.0可选的out / ref参数 [英] C# 4.0 optional out/ref arguments

查看:313
本文介绍了C#4.0可选的out / ref参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C#是否允许可选的 out ref 参数?

解决方案

如前所述,这是不允许的,我认为这是一个很好的意义。
不过,要添加一些详细信息,请查看 C# 4.0规范,第21.1节:


构造函数,方法,索引器和委托类型可以声明为可选的:



固定参数:

&  属性 opt parameter-modifier opt type identifier default-argument opt

默认参数:

    = expression




  • 使用默认参数的固定参数 strong>可选参数,而不带默认参数固定参数必需参数

  • 必需的参数不能出现在 formal-parameter-list 中的可选参数之后。

  • A ref out 参数不能有
  • Does C# 4.0 allow optional out or ref arguments?

    解决方案

    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.

    这篇关于C#4.0可选的out / ref参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆