Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What does VB.NET Property process mean?

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article is to share with you about what the VB.NET Property process means. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

An attribute procedure is a series of Visual Basic statements that manipulate custom properties on a module, class, or structure. The VB.NET Property procedure is also known as the property accessor.

Visual Basic provides the following property procedures:

The Get procedure returns the property value. This procedure is called when the property is accessed in an expression.

The Set procedure sets the property to a value, including object references. When a value is assigned to an attribute, it is called.

Usually VB.NET Property procedures are defined in pairs using Get and Set statements, but if the attribute is read-only (Get statement) or write-only (Set statement (Visual Basic)), you can define the procedure independently.

You can define properties in classes, structures, and modules. By default, the property is Public, which means that they can be called from anywhere in the application of the container that can access the property.

For a comparison of attributes and variables, see differences between attributes and variables in Visual Basic.

Declaration syntax

Each parameter is declared in the same way as the Sub procedure, but the delivery mechanism must be ByVal.

The syntax for each parameter in the parameter list is as follows:

[Optional] ByVal [ParamArray]

Parametername As datatype

If the parameter is optional, you must also provide a default value as part of the declaration. The syntax for specifying the default value is as follows:

Optional ByVal parametername

As datatype = defaultvalue

Attribute value

The VB.NET Property procedure can be implicitly called by referencing the property. Property names are used in the same way as variable names, except that values for all non-optional parameters must be provided and the parameter list must be enclosed in parentheses. If no parameters are provided, you can also choose to omit the parentheses.

The syntax for implicitly calling a Set procedure is as follows:

Propertyname [(argumentlist)]

= expression

The syntax for implicitly calling a Get procedure is as follows:

Lvalue = propertyname

[(argumentlist)]

Do While (propertyname

[(argumentlist)] > expression)

Declaration and invocation interpretation

The following attribute stores a full name as two names (first name and last name) that make up the full name. When the calling code reads the fullName, the Get procedure combines the two components of the name and returns the full name. When the calling code is given a new full name, the Set procedure attempts to split it into two parts of the name. If it does not find a space, it is stored as a name.

Visual Basic Dim firstName, lastName As String Property fullName () As String Get If lastName = "" Then Return firstName Else Return firstName & "& lastName End If End Get Set (ByVal Value As String) Dim space As Integer = Value.IndexOf (") If space < 0 Then firstName = Value lastName ="Else firstName = Value.Substring (0, space) lastName = Value.Substring (space + 1) End If End Set End Property

The following example demonstrates a typical call to a VB.NET Property procedure.

Visual Basic

FullName = "MyFirstName

MyLastName "

MsgBox (fullName)

Thank you for reading! This is the end of this article on "what is the meaning of the VB.NET Property process?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report