【发布时间】:2014-01-05 04:55:06
【问题描述】:
复制真的很简单,输出很奇怪;
预期的输出是“bbb bbb” 实际输出为“aaa bbb”
有人对这种行为有任何 MSDN 解释吗?我找不到。
((a)new b()).test();
new b().test();
public class a
{
public virtual void test(string bob = "aaa ")
{
throw new NotImplementedException();
}
}
public class b : a
{
public override void test(string bob = "bbb ")
{
HttpContext.Current.Response.Write(bob);
}
}
【问题讨论】:
-
是否 ((a)(new b())).test() 给出了你想要的结果?
-
根据谁的预期输出?
-
我认为在重写方法时更改可选参数的默认值是无效的。这不会改变方法签名吗?
-
@user1567896 如果它无效,我怀疑它会
-
@Frederik 这不是无效,只是可能不明智。
标签: c# default-parameters