There is actually a really good reason for this behavior. Consider the following code.
public interface IA
{
IA DoSomething();
}
public interface IB
{
IB DoSomething();
}
public class Test : IA, IB
{
public IA DoSomething() { return this; }
IA IA.DoSomething() { return this; }
IB IB.DoSomething() { return this; }
}
In this scenario the Test
class must implement at least one of the DoSomething
methods explicitly because it is not legal to declare two different methods with the same signature. If you were to examine the IL you would see that explicitly implementing an interface decorates the member name automatically so that no two members with the same name exist in the same class. And to be able to call each of the 3 different DoSomething
variations above you have to invoke the member from a reference of the correct type. That is how the compiler knows to bind to the correct member.
public static void Main()
{
var test = new Test();
test.DoSomething(); // Compiler binds to the implicit implementation.
var a = (IA)test;
a.DoSomething(); // Compiler binds to the IA implementation.
var b = (IB)test;
b.DoSomething(); // Compiler binds to the IB implementation.
}