vb.net:接口中的多重继承 [英] vb.net: multiple inheritance in an interface

查看:249
本文介绍了vb.net:接口中的多重继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VB.net中遇到有关多重继承的问题:

I'm facing a problem regarding multiple inheritance in VB.net:

据我所知,VB.net一般不支持多重继承,但你可以通过使用接口来实现一种多重继承(使用Implements而不是Inherits):

As far as I know VB.net does not support multiple inheritance in general but you can reach a kind of multiple inheritance by working with interfaces (using "Implements" instead of "Inherits"):

Public Class ClassName
    Implements BaseInterface1, BaseInterface2

End Class

这适用于类,但我希望有一个继承一些基接口的接口。类似的东西:

That works fine for classes but I’d like to have an interface inheriting some base interfaces. Something like that:

Public Interface InterfaceName
    Implements BaseInterface1, BaseInterface2

End Interface

但接口不允许使用Implements关键字(当然有意义)。我尝试使用一种我从Java中知道的抽象类:

But the "Implements" keyword is not allowed for interfaces (what makes sense, of course). I tried to use a kind of abstract class which I know from Java:

Public MustInherit Class InterfaceName
    Implements BaseInterface1, BaseInterface2

End Class

但现在我需要实现定义的方法InterfaceName类中的BaseInterface1和BaseInterface2。但是由于InterfaceName也应该是一个接口,我不想在该类中实现这些方法。

But now I need to implement the defined methods from BaseInterface1 and BaseInterface2 within the InterfaceName class. But as InterfaceName should be an interface, too, I don’t want to have to implement these methods within that class.

在C#中你可以很容易地做到这一点: / p>

In C# you can do that quite easy:

public interface InterfaceName: BaseInterface1, BaseInterface2 {}

你知道我是否可以在VB.net中做类似的事情吗?

Do you know if I can do something similar in VB.net?

推荐答案

与Java类似,在VB.NET界面中扩展其他接口。这意味着他们继承了他们的功能。他们没有实现它。

Similar to Java, in VB.NET interfaces "extend" other interfaces. That means they "inherit" their functionality. They do not implement it.

Public Interface InterfaceName
    Inherits BaseInterface1, BaseInterface2
End Interface

这篇关于vb.net:接口中的多重继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆