C#4.0可选的out / ref参数 [英] C# 4.0 optional out/ref arguments
问题描述
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
orref
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
orout
parameter cannot have a default-argument.
这篇关于C#4.0可选的out / ref参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!