Multiple inheritance is not supported in C #.
But if you want to “inherit” behavior from two sources, why not use combos:
Composition
and
Dependency Injection
There is a basic, but important, principle of OOP that states: "Make composition over inheritance."
You can create a class as follows:
public class MySuperClass { private IDependencyClass1 mDependency1; private IDependencyClass2 mDependency2; public MySuperClass(IDependencyClass1 dep1, IDependencyClass2 dep2) { mDependency1 = dep1; mDependency2 = dep2; } private void MySuperMethodThatDoesSomethingComplex() { string s = mDependency1.GetMessage(); mDependency2.PrintMessage(s); } }
As you can see, dependencies (actual interface implementations) are introduced through the constructor. You class does not know how each class is implemented, but it knows how to use them. Therefore, there is a loose connection between the classes involved here, but with the same degree of use.
Today, trends show that inheritance is a kind of “out of fashion”.
source share