Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Implements statement in VB.NET

2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail how to use the Implements sentence in VB.NET. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

The syntax used by VB.NET to implement the interface is Implements invented by VB5, which is used in today's mainstream languages. For example, I have two interfaces:

Interface Interface1 Sub Test () End InterfaceInterface Interface2 Sub Test () End Interface

The two interfaces have exactly the same member Test. Suppose I need to use the same class to implement two interfaces at the same time? Come to think of it, in a language like Java,JScrip.NET, only one Test function can be used to implement Test members of two interfaces. If the two Test are just accidental duplicates, what if their contents must be implemented separately, so some designs to solve the interface duplicates appear. The VB.NET Implements statement allows you to implement the interface as much as you want. For example, the following class Implementation implements two interfaces with two fundamentally different names.

Public Class Implementation Implements Interface1, Interface2 Public Sub Hello () Implements Interface1.Test End Sub Private Sub Hi () Implements Interface2.Test End Sub End Class

That is, VB allows you to implement members of an interface with functions of any name, and the accessor can be arbitrary, such as Public or Private. C # provides an explicit implementation (explicit implementation) syntax for handling duplicate members, and the syntax for implementing the above two interfaces is

Public class Class1: Interface1, Interface2 {public Class1 {} void Interface1.Test {} void Interface2.Test {}}

Note here that C # can only use the interface name. The name of the member is used to name the implementation method, and the accessor can only be private, and the explicitly implemented method cannot be exposed.

After looking at IL, I found that .NET supports both implicit and explicit implementation. The implicit implementation only needs to put a method in the class with the same name as the interface member method-this type of VB is not supported. The explicit implementation adds to the method description:

.override TestApp.Interface1::Test

This is the end of the article on "how to use Implements sentences in 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 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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report