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

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

问题描述

C# 4.0 是否允许可选的 outref 参数?

Does C# 4.0 allow optional out or ref arguments?

推荐答案

正如已经提到的,这根本是不允许的,我认为这是非常有意义的.但是,要添加更多详细信息,这里引用了 C# 4.0 规范,第 21.1 节:

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:

固定参数:
  属性opt 参数修饰符opt 类型标识符默认参数opt
默认参数:
  = 表达式

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

  • 带有默认参数固定参数可选参数,而固定参数没有默认参数必需参数.
  • 必需参数不能出现在形式参数列表中的可选参数之后.
  • refout 参数不能有 default-argument.
  • 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天全站免登陆