简体   繁体   中英

How can I make a class both implement an Interface and inherit from another class

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
{
    ...
}

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 .

公共子类:BaseClass,IInterface

是的,您可以两者都做,但是必须将基类放在首位:

public partial class ObjectiveDetail : AuditableTable, IEquatable<ObjectiveDetail>

首先是基类,然后是Interface,应该可以工作

没有什么可以阻止您实现接口和从同一类中的类继承,C#仅不支持多重继承(从多个不同的类继承),因此您无需执行任何操作,它应该可以工作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM