The following works in C#:
interface I
{
int X { get; }
}
class C : I
{
public int X
{
get { ... }
set { ... }
}
}
The following does not work in VB.NET:
Interface I
ReadOnly Property X As Integer
End Interface
Class C
Implements I
Public Property X As Integer Implements I.X
Get
...
End Get
Set(value As Integer)
...
End Set
End Property
End Class
The error message Implementing property must have matching 'ReadOnly' or 'WriteOnly' specifiers is pretty self-explanatory, so I do know what’s wrong here. It’s also not a big issue, because it’s quite easy to work around this limitiation.
I’m curious, though: Does anyone know why the VB designers decided to treat this case differently than in C#?
I’m not sure about the VB side, but with the explicit interface implementation of I.X in C# you’d also get a complaint about the added setter:
You get a similar error in C#. For the VB, may want to check out this SO thread: If an interface defines a ReadOnly Property, how can an implementer provide the Setter to this property?