I’ve been having a look at explicit interface implementations in IL. The method Method in the following class (interface IA has a single Method() on it):
public class B : IA
object IA.Method() {
/* code */
}
}
is compiled to the following IL method signature:
.method private hidebysig newslot virtual final instance object IA.Method() cil managed {
.override IA::Method
/* code */
}
My question is – why is the method name in IL IA.Method(), rather than just straight Method? What does this actually mean, and why doesn’t it work if it’s missed off? I can’t find anything in the ECMA spec or google about it.
This is because this way you can have a method multiple times.
The first is a normal method. The second is the interface implementation. Without the prefix you could not have both because you could not differentiate between them.