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--
This article mainly shows you "how to use VB. NET local static variables", the content is simple and easy to understand, clear organization, I hope to help you solve doubts, let Xiaobian lead you to study and learn "VB. NET local static variables how to use" this article bar.
VB. NET Local Static Variables
VB supports declaring local variables with the Static keyword, so that the variable's value can be preserved at the end of the procedure:
Public TestSub 1 () Static i As Integer i += 1 'Implement a procedure call counter End Sub
We implemented a simple process counter. Each time Test is called, the counter is incremented by 1. There are a lot of situations where we want to keep the value of a variable. C#static cannot be used inside a procedure. So to implement a procedure counter, we must declare a class-level variable. This is obviously not as good as VB. Because there is no way to prevent other procedures from modifying counter variables. It's the same with object encapsulation, which is supposed to be a local variable of a method, and now I'm forced to separate it out, which is obviously bad design. So how does VB generate local static variables? Compiling back the above code, we can clearly see that in the CIL generated by VB, i does not appear as a local variable, but as a Field of the class:
.field private specialname int32 $STATIC$Test1$2001$i
That is, i is renamed as a field of a class, but labeled specialname. Attempting to access $STATIC$Test1$2001$i in code is impossible because it is not a valid identifier. But in IL, the code that increments this variable by one is exactly the same as a normal class field, loaded via ldfld. I think it's clever to turn a static variable into a class field with the same life cycle, but let the compiler control access and make it a local variable. It also explains why VB uses two different keywords to declare static variables- Static and Shared.
Because VB. NET local static variables are essentially class fields, they are different from real local variables. For example, under multithreaded conditions, access to VB. NET local static variables is the same as access to fields.
The above is "VB. NET local static variables how to use" all the contents of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to 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.