用其他语言,我可以像这样设置方法签名
cookEgg(boolean hardBoiled = true)
如果我在方法调用中没有收到参数,这会将参数hardboiled
缺省为true
。
我将如何在C#中实现?
void cookEgg(bool hardBoiled) { ... }
void cookEgg() { cookEgg(true); }
C#4.0将添加可选参数-您将能够完全像原始示例中那样编写代码,并且它将按预期工作。
void test(params int []arg) { }