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.

  1. namespace ConsoleApplication1  
  2. {  
  3.     interface IShow  
  4.     {  
  5.         void Show();  
  6.     }    
  7.     interface IShow_Case  
  8.     {  
  9.         void Show();  
  10.     }  
  11.     class B : IShow, IShow_Case  
  12.     {  
  13.         public void IShow.Show()  
  14.         {  
  15.             Console.WriteLine("IShow Interface function");  
  16.         }    
  17.         public void IShow_Case.Show()  
  18.         {  
  19.             Console.WriteLine("IShow_Case Interface function");  
  20.         }   
  21.         static void Main(string[] args)  
  22.   
  23.         {  
  24.             IShow I = new B();  
  25.             I.Show();  
  26.             IShow_Case I1 = new B();  
  27.             I1.Show();  
  28.             Console.ReadKey(true);  
  29.         }  
  30.     }    
  31. }  
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. 

  1. void IShow.Show()  
  2. {  
  3.      Console.WriteLine("IShow Interface function");  
  4. }  
  5. void IShow_Case.Show()  
  6. {  
  7.     Console.WriteLine("IShow_Case Interface function");  
  8. }
Image2.jpg