Auto-implemented Properties
Developers often need to create simple entity classes or containers for data, in which the properties defined follow a very simple structure:
Private _FirstName As String
Property FirstName() As String
Get
Return _FirstName
End Get
Set(ByVal value As String)
_FirstName = value
End Set
End Property
Auto-implemented properties provide a simple one-line way of expressing this concept:
Property ID() As Integer
Property FirstName() As String
Property LastName() As String
In this case the compiler will generate a backing field with the same name as the property, but with a preceding underscore. It will also fill in the property’s getter and setter.
Initializers can be used to give an auto-implemented property a default value (which gets set in the class’ constructor):
Property ID() As Integer = -1
Property SupplierList() As New List(Of Supplier)
Property OrderList() As New List(Of Order) With {.Capacity = 100}
<DefaultValue("-")>
Property Name() As String Implements ICustomer.Name
Auto-implemented properties cannot have parameters, nor can they be declared ReadOnly or WriteOnly.