Inherit Multiple Interfaces and They have Conflicting Method Name

Here we discuss on 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 below image.

Image1.jpg

 
Here you need to remove Public modifier from the methods, because it implement by using interface name to differentiate same  method by their interface. We know interface by default Public so we need to remove Public modifier from the methods.  

void IShow.Show()

{
     Console.WriteLine("IShow Interface function");

}

void
IShow_Case.Show()
{

    Console.WriteLine("IShow_Case Interface function");

}

Image2.jpg
Ebook Download
View all
FileInfo in C#
Read by 9.7k people
Download Now!
Learn
View all