In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
How to understand the optional parameters of VB.NET, in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
VB.NET is still quite commonly used, so I studied the optional parameters of VB.NET and shared them with you here. I hope it will be useful to you. VB has supported the optional parameter feature since 4. 0. That is, some of the parameters of the function or subroutine are optional and can be called without input. In fact, VB has had some functions with optional parameters since 1. 0, but users are not allowed to develop such a process until 4. 0. In VB4, optional parameters can be without default values, while in VB.NET, if optional parameters are used, they must have default values. Such as
Public Sub TestOptional (Optional i As Integer = 1) End Sub
When called, it can be written as either TestOptional (2) or TestOptional (), in which case the parameter I is automatically equal to 1. If the procedure has more than one VB.NET optional parameter, VB also provides a way to simplify the operation by passing parameters by name. Like the process.
Public Sub TestOptional (Optional i As Int32 = 1, Optional j
As Int32 = 1, Optional k As Int32 = 1)
End Sub
If you only want to specify k and let I and j use the default values, you can use passing by name, as follows
TestOptional (k: = 2)
And this method is not limited by the order of the parameter table.
TestOptional (k: = 2, I: = 3, j: = 5)
These are indeed quite convenient features, and C# does not support the above two features. Let's see how it is implemented at the IL level. The above * * methods are defined in IL as
.method public instance void TestOptional ([opt] int32 I) cil managed {.param [1] = int32 (0x00000001) .maxstack 8
As you can see, the parameter is appended with the [opt] modifier, and .param specifies the default value of the parameter. This is content that only VB can recognize, and C# will skip them. When called, if VB finds that the parameter is omitted, it automatically reads the default value of the .param section and explicitly passes it to the procedure. This part is handled entirely by the compiler without any performance loss and is exactly the same as passing all parameters manually. As for passing by name, VB automatically adjusts the order of parameters, and the result is no different from the traditional way of passing. This shows that we can safely use this convenience. And the process with VB.NET optional parameter gets to C #, at best, it becomes non-VB.NET optional parameter, and it won't cause any other trouble.
This is the answer to the question on how to understand the optional parameters of VB.NET. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
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.