Reputation: 35605
This is allowed:
Public Property Text() As String
Whereas for a read-only property why aren't I allowed an equivalent?
Public ReadOnly Property Text() As String
I seem to be forced to use:
Public ReadOnly Property Text() As String
Get
Return fText
End Get
End Property
Upvotes: 4
Views: 2100
Reputation: 172478
It is now supported in VB14 (Visual Studio 2015 and later). Auto-implemented properties can be initialized with initialization expressions:
Public ReadOnly Property Text1 As String = "SomeText"
Public ReadOnly Property Text2 As String = InitializeMyText()
or in the constructor:
Public ReadOnly Property Text As String
Public Sub New(text As String)
Me.Text = text
End Sub
Details:
Upvotes: 5