I have asked my colleagues at work and even tried to look up this on the internet but I haven't been able to get an answer.
What is the difference between
Public Property Name As String
and
Public Property Name() As String
What difference makes adding () after the property name?
In visual basic, properties will enable the class variables to expose in public way using Get and Set accessors with Property keyword by hiding implementation details. In properties, the Get accessor is useful to return the property value and the Set accessor is useful to assign a new value.
A property member is implemented as a Private member variable together with a special type of VB function that incorporates both accessor functions of the property.
First of all you may find it that Property has many similarities to Methods. from this prospective, parenthesis in Property used for parameters. if a Property has no parameter you can omit it. following is the full property declaration syntax:
[Default] [Modifiers] Property PropertyName[(ParameterList)] [As DataType]
[AccessLevel] Get
' Statements of the Get procedure.
' The following statement returns an expression as the property's value.
Return Expression
End Get
[AccessLevel] Set[(ByVal NewValue As DataType)]
' Statements of the Set procedure.
' The following statement assigns newvalue as the property's value.
LValue = NewValue
End Set
End Property
You may find valuable tips in following links: What is the difference between a parameterized property and function in vb.net? AND https://msdn.microsoft.com/en-us/library/e8ae41a4.aspx
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