Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vb.Net Properties Syntax

Tags:

.net

vb.net

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?

like image 516
jecarfor Avatar asked Apr 08 '15 12:04

jecarfor


People also ask

How do you use properties in Visual Basic?

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.

How are properties implemented in a VB.NET class?

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.


1 Answers

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

like image 155
Vahid Farahmandian Avatar answered Nov 03 '22 01:11

Vahid Farahmandian