真的很容易复制,输出是奇怪的;覆盖C#中的默认参数
预计输出为 “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()给出你想要的结果吗? – rhughes
根据* who *?的预期输出 – Jamiec
我相信在重写方法时更改可选参数的默认值是无效的。这不会改变方法签名吗? –