Implementing an interface?

D

David Veeneman

I'm new to VB.NET, and I am translating an object model from C# to VB.NET,
and I have come across an odd problem implementing an interface.

The interface is a custom interface, IDrillDown, which declares one
read-only property with the following VB.NET signature:

Public ReadOnly Property ActiveText() As String

I have declared the interface in the class declaration, like this:

Public Class CustomerItem
Implements IDrillDown

...

End Class

Later in the class, I implement the interface by by declaring my ActiveText
property:

Public ReadOnly Property ActiveText() As String
Get
Return Me.Name
End Get
End Property

VB.NET is giving me a compile-time error, saying that the class must
implement the ActiveText property for the IDrillDown interface. Needless to
say, I am puzzled, since I have implemented the property with the signature
required by the interface.

Can anyone shed some light on this? Thanks.
 
T

Tom Shelton

David said:
I'm new to VB.NET, and I am translating an object model from C# to VB.NET,
and I have come across an odd problem implementing an interface.

The interface is a custom interface, IDrillDown, which declares one
read-only property with the following VB.NET signature:

Public ReadOnly Property ActiveText() As String

I have declared the interface in the class declaration, like this:

Public Class CustomerItem
Implements IDrillDown

...

End Class

Later in the class, I implement the interface by by declaring my ActiveText
property:

Public ReadOnly Property ActiveText() As String
Get
Return Me.Name
End Get
End Property
David -

Public ReadOnly Property ActiveText() As String Implements
IDrillDown.ActiveText
Get
Return Me.Name
End Get
End Property

HTH,
 
P

Phill W.

David said:
The interface is a custom interface, IDrillDown
Public ReadOnly Property ActiveText() As String
Public ReadOnly Property ActiveText() As String
Get
Return Me.Name
End Get
End Property

VB.NET is giving me a compile-time error, saying that the class must
implement the ActiveText property for the IDrillDown interface.

You have created a method that can implement th Interface's property,
but you haven't told VB to connect to two.
Interface implementations are explicit, so you have to add the
"Implements [Interfacename].[MethodName]" clause.

It allows you to do funny things like this :

Private ReadOnly Property Message() As String _
Implements I.ActiveText

Yes, that's a Private property, implementing a Public Interface property
with a totally /different/ name (but /same/ signature, otherwise).

HTH,
Phill W.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top