本文介绍了C# 4.0 可选的 out/ref 参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
C# 4.0 是否允许可选的 out
或 ref
参数?
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:
构造函数、方法、索引器和委托类型的形式参数可以声明为可选:
固定参数:
属性 参数修饰符 类型标识符默认参数
默认参数:
= 表达式
fixed-parameter:
attributes parameter-modifier type identifier default-argument
default-argument:
= expression
- 带有默认参数的固定参数是可选参数,而固定参数没有默认参数是必需参数.
- 必需参数不能出现在形式参数列表中的可选参数之后.
ref
或out
参数不能有 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
orout
parameter cannot have a default-argument.
这篇关于C# 4.0 可选的 out/ref 参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!