I have a doubt on how to call the method of particular interface (Say IA or IB or In...) in the following code. Please help me on how to call. I have commented the lines of
You need to use explicit interface implementation for this process.
If the two interface members do not perform the same function, however, this can lead to an incorrect implementation of one or both of the interfaces. It is possible to implement an interface member explicitly—creating a class member that is only called through the interface, and is specific to that interface. This is accomplished by naming the class member with the name of the interface and a period.
interface IA
{
void Display();
}
interface IB
{
void Display();
}
public class Program:IA,IB
{
void IA.Display()
{
Console.WriteLine("I am from A");
}
void IB.Display()
{
Console.WriteLine("I am from B");
}
public static void Main(string[] args)
{
IA p1 = new Program();
p1.Display();
IB p2 = new Program();
p2.Display();
}
}
Output will be:
I am from A
I am from B
Here is a DEMO.