VB.Net Member Property
VB.Net uses a special property keyword along with special get and set methods to both get and set the values of properties. For a read-only property, leave out the set method. The value keyword is used to refer to the member field. Properties can make use of any of the access modifiers (private, protected, etc).
My preference for VB.Net code is to start member fields with "F" ("FName" in our example) and drop the "F" with properties that manage member fields ("Name" in our example).
Syntax Example: Public Class Cyborg
Private FCyborgName As String
Public Property CyborgName()
Get
Return FCyborgName
End Get
Set(ByVal value)
FCyborgName = value
End Set
End Property
End Class
Complete Example
Refer to our VB.Net Class..Object post for an example.
Rumor Mill: Auto-Implemented Properties in VB.Net 10.0
It is widely rumored that the next version of VB.Net will include auto-implemented properties. Currently C# 3.0 and later offer this feature as follows:
//C# auto-implemented property.
pulic int VendorID {get; set;}
The next version of VB.Net is rumored to offer a similar syntax feature:
'VB.Net auto-implemented property.
Public Property VendorID() As Integer
In addition, it is rumored that the next version will allow you to iniatilize the property which is something C# does not allow.
'Initialized auto-implemented properity.
Public Property VendorID() As Integer = -1
This is important and useful when no additional logic is required for a property. Soon properties will be just as easy to create as a member field and have an equivalent compact form (a single line of code).