How can I convert following code to VB.NET?
class A
{
public int NumberA { get; set; }
}
class B : A, I
{
public int NumberB { get; set; }
}
interface I
{
int NumberA { get; set; }
int NumberB { get; set; }
}
In VB.NET there is problem with Implements keyword after property declaration. So I need to do something like this:
Class B
Inherits A
Implements IC
Public Property NumberB() As Integer Implements IC.NumberB
Get
Return m_NumberB
End Get
Set(ByVal value As Integer)
m_NumberB = value
End Set
End Property
Private m_NumberB As Integer
Public Property NumberA1() As Integer Implements IC.NumberA
Get
Return MyBase.NumberA
End Get
Set(ByVal value As Integer)
MyBase.NumberA = value
End Set
End Property
End Class
But there is duplicit misleading property NumberA1. Is there some way how to do it more clever?
Yes, not supported in vb.net. The compiler requires the interface to be implemented with an explicit Implements keyword, unlike C#. The closest you could get is:
Note that B now no longer needs to implement NumberA even though it implements ICA, the implementation in A is accepted. But of course that requires way too much tinkering with the original definitions. The workaround you used is good and has no detrimental effects at runtime. Note that you can make A1 private.