In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how VB.NET to achieve process overloading, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
VB.NET procedure overloading refers to defining a procedure in multiple versions with the same name and different parameter lists. The purpose of overloading is to define several closely related versions of the process without distinguishing them by name, which can be done by changing the parameter list.
VB.NET procedure overloading rules
Suppose you want to write a Sub process to advertise transactions based on the customer's balance, and you want to be able to reference the customer by name or by account. To do this, you can define two different Sub procedures, as shown in the following example:
Visual Basic
Sub postName (ByVal custName
As String, ByVal amount
As Single)
'Insert code to access
Customer record by
Customer name.
End Sub
Sub postAcct (ByVal custAcct
As Integer, ByVal
Amount As Single)
'Insert code to access
Customer record by account number.
End Sub
VB.NET process reload version
Another way is to overload a separate procedure name. You can use the Overloads keyword to define a version of the procedure for each parameter list, as follows:
Visual Basic
Overloads Sub post (ByVal
CustName As String, ByVal
Amount As Single)
'Insert code to access
Customer record by
Customer name.
End Sub
Overloads Sub post (ByVal
CustAcct As Integer
ByVal amount As Single)
'Insert code to access
Customer record by
Account number.
End Sub
Other VB.NET process overloads
If you also need to accept the transaction amount expressed in Decimal or Single, you can further overload the post to allow this change. If you did this for each overload in the example above, there would be four Sub procedures with the same name but four different signatures.
Advantages of VB.NET process overloading
The advantage of overloading procedures is that they make calls more flexible. To use the post procedure declared in the previous example, the calling code can obtain a customer identity of type String or Integer, and then call the same procedure in both cases. The following example illustrates this:
Visual Basic
Imports MSvb = Microsoft.
VisualBasic
Visual Basic
Dim customer As String
Dim accountNum As Integer
Dim amount As Single
Customer = MSVB.Interaction.
InputBox ("Enter customer name"
Or number ")
Amount = MSVB.Interaction.
InputBox ("Enter transaction"
Amount ")
Try
AccountNum = CInt (customer)
Call post (accountNum, amount)
Catch
Call post (customer, amount)
End Try
Thank you for reading this article carefully. I hope the article "how to achieve process reloading in VB.NET" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.