In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how to create VB.NET method, the article is very detailed, has a certain reference value, interested friends must read it!
The method creation in VB.NET is the same as in VB6, you can use the Sub or Function keyword. The difference between Sub and Function is that if you create a method with Sub, it will not return a numeric value; if you create a method with Function, it will return a numeric value as a result. For example, the VB.NET method creates:
Sub MyWorks () End Sub Function MyValue () As Integer End Function
We can still use the scope keyword in VB.NET, which is similar to that in VB 6, but with Protected. Specific domain keywords are:
Private indicates that only code in the class can be called
Friend indicates that code can be invoked in our project / component
Public indicates that code can be called outside of our class
Protected is a new addition to VB.NET, which we will elaborate on when we discuss inheritance.
Protected Friend indicates that code can only be called in our project / component as well as in our Subclass code. Similarly, we will elaborate on it when we discuss inheritance.
By default, the parameter to the method is declared as ByVal instead of ByRef. Of course, we can still override this default behavior by using the ByRef keyword.
VB.NET method to create properties
In the past, we used Property Get and Property Let to create properties, but now we have integrated it into a structure in VB.NET. Examples are as follows:
Private mystrName As String Public Property Name () As String Get Return mystrName End Get Set mystrName = Value End Set End Property
Default properties of the VB.NET method
When creating a class in VB6, we can declare a default method or property for the class. To do this, you can choose from the menu: Tools (tools)-> Procedure Attributes (process properties) and set Procedure ID to the default.
VB.Net changes this behavior in two ways. *, use a default keyword to create default properties to make the declaration more clear and intuitive. However, VB.NET also introduces a new restriction on the default attribute, that is, the attribute must be an array of attributes.
An array of attributes is actually like an array, with an index. An example is an item property in a selection or list object:
StrText = MyList.Item (5)
This project property does not have a single value, but has a set of properties that can be accessed by index.
By using the attribute array as the default attribute, we allow the programming language to avoid ambiguity in using the default attribute. As we know in VB6, the limitation of the keyword Set is the key. Let's take a look at the following statement:
MyValue = MyObject
Does this sentence refer to the object MyObject or its default attribute? To recognize it, the Set command is used in VB6 to deal with objects, and if you don't use Set, you mean the default properties. In VB.NET, this statement refers to objects because the default properties are indexed. To get the default properties, we need to write the following code:
MyValue = MyObject (5)
Because the index is a clear indicator (we mean the default attribute, not the MyObject itself), there is no polysemy.
A change like VB.NET means that the property array procedure must receive a parameter. For example
Private MyMoney (100) As String Default Public Property Money (ByVal Index As Integer) As String Get Money = MyMoney (index) End Get Set MyMoney (index) = Value End Set End Property
* this code looks clearer than VB6, but it also loses some flexibility. In the past, we liked to use default properties. For example, we often use default properties, such as default text properties, when using GUI controls.
TextBox1 = MyText
But this is no longer valid in VB.NET because text attributes are no longer an array of attributes. Instead, we have to use attribute names.
The above is all the content of the article "how to create a VB.NET method". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.