Here we discuss Inherit multiple interfaces with conflicting method names within the C#, part of the Software Development category; what happens if you inherit multiple interfaces and they have conflicting method names? Interface IShow { void Show();} interface IShow_Case { void Show();} Describe the implementation.
namespace ConsoleApplication1
{
interface IShow
{
void Show();
}
interface IShow_Case
{
void Show();
}
class B : IShow, IShow_Case
{
public void IShow.Show()
{
Console.WriteLine("IShow Interface function");
}
public void IShow_Case.Show()
{
Console.WriteLine("IShow_Case Interface function");
}
static void Main(string[] args)
{
IShow I = new B();
I.Show();
IShow_Case I1 = new B();
I1.Show();
Console.ReadKey(true);
}
}
}
When you compile this program you will get an error display in the below image.
Here you need to remove the Public modifier from the methods because it is implemented by using the interface name to differentiate the same method by their interface. We know the interface by default Public so we need to remove the Public modifier from the methods.
void IShow.Show()
{
Console.WriteLine("IShow Interface function");
}
void IShow_Case.Show()
{
Console.WriteLine("IShow_Case Interface function");
}