Domanda

I want my class to implement an interface and also get the additional properties from Auditable table. Can I do both? I have tried to do it here but I am getting an error in my IDE.

public partial class ObjectiveDetail : IEquatable<ObjectiveDetail>, AuditableTable
{
    ...
}

public abstract class AuditableTable : IAuditableTable
{
    ...
}
È stato utile?

Soluzione

You must change

public partial class ObjectiveDetail : IEquatable<ObjectiveDetail>,  AuditableTable

to

public partial class ObjectiveDetail :   AuditableTable, IEquatable<ObjectiveDetail>

In C#, you can inherit one class and implement multiple interfaces and you must put class first.

Altri suggerimenti

public SubClass : BaseClass, IInterface

Yes you can do both, but you have to put the base class first:

public partial class ObjectiveDetail : AuditableTable, IEquatable<ObjectiveDetail>

Base class first and then Interface, should work

Nothing prevents you from both implementing an interface and inheriting from a class in the same class, C# only doesn't support multiple inheritance (inheriting from multiple diferent classes) so you don't need to do anything, it should just work.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top