In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail what are the applicable rules for the default attributes of VB.NET. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
The emergence of the VB.NET programming language helps developers easily achieve many functions, and we can use it to help us improve our programming efficiency. In VB.NET, properties that accept parameters can be declared as the VB.NET default property of the class. The default property is the property that Microsoft Visual Basic .NET will use when a specific property is not named for the object. Default properties are useful because they allow you to simplify the source code by omitting common property names.
The properties that are most appropriate as default properties are those that accept parameters and you think will be the most commonly used. For example, the Item property is a good choice for the default property of a collection class because it is often used.
The following rules apply to the VB.NET default properties:
A type can have only one default property, including properties inherited from the base class. There is one exception to this rule. The default property defined in the base class can be hidden by another default property in the derived class.
If the default property in the base class is hidden by a non-default property in the derived class, the default property can still be accessed using the default property syntax.
The default property cannot be Shared or Private.
If an overloaded property is the VB.NET default property, all overloaded properties with the same name must also specify Default.
The default property must accept at least one parameter.
The following example declares a property that contains an array of strings as the default property of the class:
Class Class2
'Define a local variable
To store the property value.
Private PropertyValues As String ()
'Define the default property.
Default Public Property Prop1
(ByVal Index As Integer) As String
Get
Return PropertyValues (Index)
End Get
Set (ByVal Value As String)
If PropertyValues Is Nothing Then
'The array contains Nothing
When first accessed.
ReDim PropertyValues (0)
Else
'Re-dimension the array to
Hold the new element.
ReDim Preserve PropertyValues
(UBound (PropertyValues) + 1)
End If
PropertyValues (Index) = Value
End Set
End Property
End Class
Access VB.NET default properties
Default properties can be accessed using acronym syntax. For example, the following code snippet uses both standard and VB.NET default property syntax:
Dim C As New Class2 ()
'The first two lines of code
Access a property the standard way.
C.Prop1 (0) = "Value One"
'Property assignment.
MessageBox.Show (C.Prop1 (0))
'Property retrieval.
'The following two lines of
Code use default property syntax.
C (1) = "Value Two"
'Property assignment.
MessageBox.Show (C / 1)
'Property retrieval.
This is the end of this article on "what are the applicable rules for the default attributes of VB.NET". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it out for more people to see.
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.