更新:2007 年 11 月
某个接口从两个接口继承,这两个接口的每个接口都声明一个同名的默认属性。编译器无法不加限定地将某个访问解析到此默认属性。下面的示例阐释这一点。
Public Interface Iface1
Default Property prop(ByVal arg As Integer) As Integer
End Interface
Public Interface Iface2
Default Property prop(ByVal arg As Integer) As Integer
End Interface
Public Interface Iface3
Inherits Iface1, Iface2
End Interface
Public Class testClass
Public Sub accessDefaultProperty()
Dim testObj As Iface3
Dim testInt As Integer = testObj(1)
End Sub
End Class
当您指定 testObj(1) 时,编译器尝试将其解析到默认属性。但是,由于是继承的接口,有两个可能的默认属性,所以,编译器会发出信号告知此错误。
**错误 ID:**BC30686
更正此错误
避免继承任何同名成员。在前面的示例中,如果 testObj 不需要任何成员(例如 Iface2 的成员),则按如下所示声明它:
Dim testObj As Iface1- 或 -
在类中实现继承接口。然后,您可以实现每个不同名称的继承属性。但是,它们中只有一个可以是实现类的默认属性。下面的示例阐释这一点。
Public Class useIface3 Implements Iface3 Default Public Property prop1(ByVal arg As Integer) As Integer Implements Iface1.prop ' Insert code to define Get and Set procedures for prop1. End Property Public Property prop2(ByVal arg As Integer) As Integer Implements Iface2.prop ' Insert code to define Get and Set procedures for prop2. End Property End Class