C# doesn't support multiple inheritances but it is been achieved using interfaces. A class in C# has the option to implement one or more interface(S). There is only one challenge when class implements multiple interfaces is that they may include methods with same name and signature as existing class members or other interfaces' members.
Explicit interface implementation gives the ability to hide the details of an interface and it is only available by casting to the interface type. Explicit interface implementation can be used to disambiguate class members and interface members otherwise they will conflict.
Lets take an example, If a class implements two interfaces that contain a member with the same signature, then implementing that member on the class will cause both interfaces to use that member as their implementation.
interface IInterfaceA
{
void Paint();
}
interface IInterfaceB
{
void Paint();
}
class SampleClassA : IInterfaceA, IInterfaceB
{
// Both IInterfaceA.Paint and IInterfaceA.Paint call this method.
public void Paint()
{
}
}
The class member IInterfaceA.Paint is only available through the IInterfaceA interface, and IInterfaceB.Paint is only available through IInterfaceB. Both method implementations are separate, and neither is available directly on the class. For example:
SampleClass obj = new SampleClass();
//obj.Paint(); // Compiler error.
IInterfaceA c = (IInterfaceA)obj;
c.Paint(); // Calls IInterfaceA.Paint on SampleClass.
IInterfaceB s = (IInterfaceB)obj;
s.Paint(); // Calls IInterfaceB.Paint on SampleClass.
It is possible to implement an interface member explicitly. Create a class member that is only called through the interface, and is specific to that interface. This can be achieved by naming the class member with the name of the interface and a period. For example:
public class SampleClass : IInterfaceA, IInterfaceB
{
void IInterfaceA.Paint()
{
System.Console.WriteLine("IInterfaceA.Paint");
}
void IInterfaceB.Paint()
{
System.Console.WriteLine("IInterfaceB.Paint");
}
}
36bd0194-55af-4db2-8d34-6058de4149d8|0|.0