How to derive two abstract classes in C#
Solution 1
You can't multiple inherit using C#. You can however achieve this by using an interface.
public interface Ia
{
}
public interface Ib
{
}
public abstract class MainProject : Ia, Ib
{
}
C# interfaces only allow signatures of methods, properties, events and indexers. You will have to define the implementation of these in the proj
(MainProgram) class.
Solution 2
public abstract class proj : a, b
This can't be done. C# doesn't allow multiple inheritance.
Solution 3
Rather than deriving from multiple abstract classes (which is illegal in C#), derive from two interfaces, (which are abstract by definition).
Solution 4
You can't derive from two classes at the same time. You should use interfaces instead.
public interface IFirstInterface
{
}
public interface ISecondInterface
{
}
public abstract class Proj : IFirstInterface, ISecondInterface
{
}
Now classes that inherit from Proj
will still need to implement all methods and properties defined in both interfaces.
user987316
Updated on June 04, 2022Comments
-
user987316 almost 2 years
I have app structure -
public abstract class a { } //defined in a.dll public abstract class b { } //defined in b.dll //Above 2 DLL reference added in main project where I want to derive both of this abstract classee like public abstract class proj : a, b { }
I am able to derive any one of it only not both. So pls guide me on missing things or wrong coding I had done.