Rushee Mahorkar

Rushee Mahorkar

  • 1.7k
  • 24
  • 619

Multiple Inheritance in C#

Jun 21 2023 4:28 PM
//Interface I1 and I2 I cant change as they are 
public interface I1
{
    void Display();
}
public interface I2
{
    void Display();
    void Display2();
}

//I can make changes here
public class MyClass : I1, I2
{
    void I1.Display()
    {
    }
    void I2.Display()
    {
    }

    void I2.Display2()
    {
        
    }
}

//Calling this method from a diffrent class
void processData(I1 data) //I have to accept I1 interface refrence only
{
    var temp = data.Display2(); //Error 
}

In processData() method data.Display2() is giving error. How I can achive as data is basically MyClass object then how can I call Display2() with I2 reference. Is there any solution like Casting or any SOLID principle which I am missing? 


Answers (3)