C# does not support multiple class inheritance. You can only implement multiple interfaces, and inherit from (extend) a single base class.
Multiple base classes for one derived class, inheritance in C#
-
30-05-2022 - |
سؤال
If I have a class with two base classes :
public partial MyClass : Base1, Base2 {
}
To call the constructor of Base1 I would do this:
public MyClass() : base(myParamForBase1);
But I need to call the second base class to get the base init value like this:
base.OnInit(e);
I cannot do the above of course because C# thinks I'm referring to Base1 not Base2, how do I resolve this? In other words how can I refer to Base2?
المحلول
نصائح أخرى
What you can do is, make a class that inherits from the first base
something like this
public Base2 : Base1 {
}
public MyClass : Base2 {
}
Not that i like this, but it may help in some cases
لا تنتمي إلى StackOverflow