In VB.NET, what are the advantages of using the Property
keyword rather than:
Private MyProperty as String
Public Sub setP(ByVal s as String)
MyProperty = s
End Function
Public Function getP() as String
return MyProperty
End Function
Coming from Java I tend to use this style rather than Property...End Property
- is there any reason not to?
You are doing the work that the compiler does. Advantages of the Property keyword:
The same declaration in VS2010 using the auto property syntax:
Public Property P As String
The compiler auto-generates the getter and setter methods and the private backing field. You refactor the accessors when necessary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With