(this is related to this other question)
If you define an Interface where there is a Property with only a getter (= ReadOnly in VB.NET), why can you define the setter in implementing classes with C# but not with VB ?
I would have thought it was defined at .NET level, and not language-specific.
Example: for this interface
'VB.NET
Interface SomeInterface
'the interface only say that implementers must provide a value for reading
ReadOnly Property PublicProperty As String
End Interface
or
//C# code
interface IPublicProperty
{
string PublicProperty { get; }
}
This is a correct implementation in C# :
public class Implementer:IPublicProperty
{
private string _publicProperty;
public string PublicProperty
{
get
{
return _publicProperty;
}
set
{
_publicProperty = value;
}
}
}
But this is invalid in VB.NET
Public Property PublicProperty As String Implements SomeInterface.PublicProperty
Get
Return _myProperty
End Get
Set(ByVal value As String)
_myProperty = value
End Set
End Property
UPDATE 2015/04/23
Turns out this feature is coming as part of VB14 ! See Languages features in C# 6 and VB 14 and New Language Features in Visual Basic 14 :
ReadOnly interface properties can be implemented by ReadWrite props This cleans up a quirky corner of the language. Look at this example:
Interface I ReadOnly Property P As Integer End Interface Class C : Implements I Public Property P As Integer Implements I.P End Class
Previously, if you were implementing the ReadOnly property I.P, then you had to implement it with a ReadOnly property as well. Now that restriction has been relaxed: you can implement it with a read/write property if you want. This example happens to implement it with a read/write autoprop, but you can also use a property with getter and setter.