It is called an explicit interface implementation . It is mainly used to disambiguate members with the same name present in different interfaces, which also need different implementations.
You have
interface ISomething1 { void DoSomething(); } interface ISomething2 { void DoSomething(); } class MyClass : ISomething1, ISomething2 { void ISomething1.DoSomething() {
Without the implementation of the Explicit interface, you cannot provide a different implementation of DoSomething for both interfaces that we implement.
If you want to implement any interface and want to hide it from the client (to some extent), you can use an explicit implementation. Array class implements the IList interface explicitly and that it hides IList.Add , IList.Remove , etc. However, you can call it if you apply it to the IList type. But in this case you will get an exception.
Members implemented through explicit implementations are not displayed through an instance of the class (even inside the class). You need to access it through an instance of the interface.
MyClass c = new MyClass(); c.DoSomething();
Sriram sakthivel
source share