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--
Today, I will talk to you about the basic concept of VB.NET dynamic interface, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.
In the application of VB.NET, a complete object-oriented language, we will come into contact with many new operation methods and coding methods, which will brighten the eyes of programmers and greatly improve the efficiency of programming. Among them, the application of VB.NET dynamic interface can help developers to accomplish some specific tasks easily.
When it comes to the difference between dynamic and static languages, there is a classic saying: Static typing when possible, dynamic typing when needed. Visual Basic supports late binding and dynamic identifiers, so you can operate according to the runtime type of the object. It's just that late binding or dynamic identifiers lack constraints on the parameter or return value type and operate only according to the name of the member.
Take an example of the VB.NET dynamic interface: in the static section, we introduced anonymous types, assuming that there are three instances of anonymous types (Tuple):
The following is a reference clip:
Dim a = New {Name: =
"Robbins", Age: = 25}
Dim b = New {Name: =
"Andrei", ID: = 12
Address: = "Beijing"}
Dim c = New {Name: =
New NameType ("Mark")
Title: = "PM"}
As you can see, the three Tuple have different types, and since anonymous types have no way to implement the interface, there is no way to manipulate the same attribute Name of an and b with the same syntax. The Name property can be accessed uniformly with late binding, but the Name property of c is different from that of Aline b, but late binding allows them to access it in a uniform way, which expands the dynamic hidden trouble.
Is there a dynamic access to members and some strongly typed constraints? Visual Basic 9.0 introduces dynamic interfaces. VB.NET dynamic interface is different from ordinary interface, the type does not need to declare to implement the dynamic interface, as long as the member with the corresponding dynamic interface definition can be converted to the dynamic interface type. This feature is also known as duck type determination. Because there is a method of dynamic language type judgment: if something walks like a duck and talks like a duck, it is a duck. The definition of a dynamic interface requires the Dynamic modifier:
The following is a reference clip:
Dynamic Interface IHasName Property Name As String End Interface
This interface specifies a property of type String named Name. Any type of instance is presumed to implement IHasName as long as it has the property Name of type String:
Dim a = New {Name: =
"Robbins", Age: = 25}
Dim b = New Button ()
{Name: = "Button1"
Text: = "Button1"}
Dim ihn As IHasName = a
Ihn.Name = "Haward"
Ihn = b
Ihn.Name = "Button2"
Although neither the anonymous type nor the Button type of a declares to implement the IHasName interface, they both have a property of type String named Name, so both can use the IHasName interface. Dynamic interfaces provide late binding with type constraints and IDE intelligence awareness, which once again improves the ability of Visual Basic dynamic programming. One caveat, though, is that VB.NET dynamic interfaces are not a type-safe feature.
After reading the above, do you have any further understanding of the basic concepts of VB.NET dynamic interfaces? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
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.