Hawkeye Hawkeye - 1 year ago 90
Vb.net Question

Difference between a one-line ReadOnly property and a ReadOnly with explicit Get statement in vb.net

I have a simple question.

Is there a difference between a one-line

ReadOnly Property
and a
ReadOnly Property
with an explicit

For example, In Visual Studio 2010 I used to have to do this:

Private _Message As String = ""

Public ReadOnly Property Message As String
Return _Message
End Get
End Property

Public Sub New(Message As String)
_Message = Message
End Sub

But now here I am in Visual Studio 2015 and it let's me get away with this:

Public ReadOnly Property Message As String

Public Sub New(Message As String)
Me.Message = Message
End Sub

Now I wasn't trying to me lazy, I just ran across it, expecting IntelliSense to force the
Statement. So I'm left wondering if there is a difference that I should be aware of. Is it bad practice or do something different?

I've managed to find tons of topics and forums about
in C#, but I seem to be coming up dry when searching the topic regarding vb.net.

I'll appreciate any input.
Thanks! =)

Answer Source

Properties without explicit getters and setters are simply a syntactic convenience. There's no difference in implementation. You should generally use the second option because it makes your code more readable. Only use the first option if you need extra functionality in the getter.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download