.netvb.netpropertiesbacking-field

VB.NET property declaration


I see we can define properties in two way in VB.NET.

As below

 Private newPropertyValue As String
    Public Property ID() As String
        Get
            Return newPropertyValue
        End Get
        Set(ByVal value As String)
            newPropertyValue = value
        End Set
    End Property

Or as below in one line

Public Property ID As String

Is there any difference or later is an improved way to define properties.


Solution

  • If you just want basic accessors use the shorthand, it sets everything up for you and is easier to read in my opinion.

    However you will need to use the standard syntax if you want to:

    Plenty of extra info here as well: https://msdn.microsoft.com/en-us/library/dd293589.aspx