C# interfaces and default parameters weirdness

Today I stumbled upon a really weird problem while using an interface with methods containing default parameters. The problem was having a default parameter value in the interface different than the implementation method's parameter. Here's an example.


public interface ITestClass
{
    string TestMethod(string name = "Name1");
}

public class TestClass : ITestClass
{
    public string TestMethod(string name = "Name2")
    {
        return name;
    }
}

class Program
{
    static void Main(string[] args)
    {
        TestClass t1 = new TestClass();
        string name1 = t1.TestMethod();
        Console.WriteLine(name1);

        // Otput is "Name2"

        ITestClass t2 = new TestClass();
        string name2 = t2.TestMethod();
        Console.WriteLine(name2);

        // Output is "Name1"
        Console.ReadKey();
    }
}


The above snippet says it all. I would expect the implementation to take precedence over the interface definition, but it all depends where you are calling your method from. And although it is debatable if this can be considered a bug, my intention was to inform the developers who spend their time scratching their heads thinking why their method does not get the correct parameter. The .NET version in question is 4.5. 


Why have default parameters in the interface in the first place


Someone might think why would you have the default values set in the interface at all. Well, it turns out that you need them there if you wish to call your implementation methods with the default parameters. If you remove the defaults, the implementation defaults do not take over and you need to input all the parameters. Thinking about it now, it seems perfectly valid, nothing takes precedence. If you have an interface type, you get the interface defaults. If you have the implementation type, you get the implementation defaults. But this is still bothering me a lot.

.Net, C#