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--
What are the characteristics of VB.NET event accessor? I believe many inexperienced people don't know what to do about it. Therefore, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
There are two important accessors in the VB.NET programming language, one is the property accessor, and the other is the VB.NET event accessor. Here we will make a detailed introduction to these two kinds of accessors, especially the related applications of VB.NET event accessors.
Accessibility of VB.NET property accessors
In the past, a problem that has been bothering me is that Get and Set accessors in VB.NET must have the same accessibility (Public, Friend, or Private). If you want to create a read-only Public property (only Get is exposed), there is no Set accessor in your component to force validation or custom property handling.
Now, the Get and Set accessors in VisualBasic2005 can set different accessibility, but Set must be more restricted in access than Get:
Private_myPropAsString PublicPropertyMyProp () AsString Get Return_myProp EndGet FriendSet (ByValvalueAsString) Ifvalue.Trim.Length > 0Then _ myProp=value.Trim Else value= "" EndIf EndSet EndProperty
This feature is useful both for team development environments and for individual developers striving for code reuse.
Customize the VB.NET event accessor
The VB.NET event accessor allows you to define a custom event, and you can control what happens when the client adds or removes an event handler and raises your event. Suppose you have a custom class in which you raise a RateChanged event. You can declare ordinary events in one of two ways:
PublicEventRateChanged ()''or PublicEventHoursChangedAsEventHandler
Declaring events in this way results in an auto-managed backup store. In other words, the system will handle the way events are hosted and dispatched. This is usually fine, but sometimes you need more control over how to notify event listeners.
You can use this new Custom keyword to define a custom event and its access modifiers. When you hit the enter key on the event declaration, VisualBasic2005 will automatically generate the code prototype for you, just like the Property accessor:
PublicCustomEventNameChangedAsEventHandler AddHandler (ByValvalueAsEventHandler)''link processor to backup storage EndAddHandler Software Development Network RemoveHandler (ByValvalueAsEventHandler)' 'remove processor EndRemoveHandler RaiseEvent (ByValsenderAsObject,ByValeAsEventArgs) from backup storage' 'activate listener EndRaiseEvent EndEvent
When the client adds or removes a handler for your event, the AddHandler or RemoveHandler process begins to operate. When the event is raised, the RaiseEvent process begins to execute. In this way, you can take special actions in the way you want to host backup storage for events. When you create these custom events in this way, you can treat the event as a property.
An example of the usefulness of a custom VB.NET event accessor is when your object is serializable and you have an event that can be handled by a non-serializable delegate object. If you try to serialize your object through a normal event, serialization will fail because the backup storage of the event is not serializable.
After reading the above, have you mastered the features of the VB.NET event accessor? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.