Reputation: 942
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.
Upvotes: 2
Views: 16904
Reputation: 70728
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.
Upvotes: 11
Reputation: 39610
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.
Upvotes: 1
Reputation: 26259
Rather than deriving from multiple abstract classes (which is illegal in C#), derive from two interfaces, (which are abstract by definition).
Upvotes: 1
Reputation: 115488
public abstract class proj : a, b
This can't be done. C# doesn't allow multiple inheritance.
Upvotes: 2