Overriding default parameters in C#

Viewed 269

Really simple to replicate, the output is bizarre;

Expected output is "bbb bbb" Actual output is "aaa bbb"

Has anyone got any MSDN explanation of this behaviour? I couldn't find any.

((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);
    }
}
1 Answers
Related