在其他语言中,我可以设置方法签名
cookEgg(boolean hardBoiled = true)
Run Code Online (Sandbox Code Playgroud)
如果我在方法调用中没有收到参数,则默认将参数hardboiled设置为true.我如何在c#中实现这一目标?
非常感谢
Pav*_*aev 31
目前,您必须重载该方法:
void cookEgg(bool hardBoiled) { ... }
void cookEgg() { cookEgg(true); }
Run Code Online (Sandbox Code Playgroud)
C#4.0将添加可选参数 - 您将能够像在原始示例中一样编写代码,并且它将按照您的预期工作.
Qry*_*taL 11
C#4(Visual Studio 2010)支持默认参数.
http://msdn.microsoft.com/en-us/library/dd264739(VS.100).aspx
| 归档时间: |
|
| 查看次数: |
15705 次 |
| 最近记录: |