In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail the example analysis of the ISpeak interface in VB.NET. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
Example of VB.NET interface
In this example, I define an interface called ISpeak, which includes three signatures (see the program below). Because an interface represents a convention or a rule, it does not contain a specific implementation of such a convention or rule. Therefore, we just need to define the signature in the interface. In this interface, three member signatures are included, which represent properties, methods, and functions.
Next, I define three more classes, Baby, Children, and Adlut, all of which implement the above interfaces. And, when each class implements the members of the interface, a specific implementation is given.
Take a look at the code:
'define an interface Public Interface ISpeak 'defines only signatures Does not contain any implementation ReadOnly Property CanSpeak () As Boolean 'attribute Sub Speak ()' method Function GetSpeakLevel () As SpeakLevelEnum 'function End Interface' speech level enumeration Public Enum SpeakLevelEnum Bad 'very bad Ordinary' general Fluent 'fluent End Enum Public Class Baby: Implements ISpeak 'implements the interface through the Implements keyword' the following are all members who implement the interface Public ReadOnly Property CanSpeak () As Boolean Implements ISpeak.CanSpeak Get Return False End Get End Property Public Function GetSpeakLevel () As SpeakLevelEnum Implements ISpeak.GetSpeakLevel Return SpeakLevelEnum.Bad End Function Public Sub Speak () Implements ISpeak.Speak Console.WriteLine (narrator): he is a baby I can't talk yet. ") End Sub End Class Public Class Children: Implements ISpeak Public ReadOnly Property CanSpeak () As Boolean Implements ISpeak.CanSpeak Get Return True End Get End Property Public Function GetSpeakLevel () As SpeakLevelEnum Implements ISpeak.GetSpeakLevel Return SpeakLevelEnum.Ordinary End Function Public Sub Speak () Implements ISpeak.Speak Console.WriteLine (", I am a happy child!") End Sub End Class Public Class Adult: Implements ISpeak Public ReadOnly Property CanSpeak () As Boolean Implements ISpeak.CanSpeak Get Return True End Get End Property Public Function GetSpeakLevel () As SpeakLevelEnum Implements ISpeak.GetSpeakLevel Return SpeakLevelEnum.Fluent End Function Public Sub Speak () Implements ISpeak.Speak Console.WriteLine ("OK, I am an adult and can speak not only my mother tongue but also a foreign language.") The entry point of End Sub End Class' program Public Class AppStart Shared Sub Main () Dim person1 As New Baby Dim person2 As New Children Dim person3 As New Adult person1.Speak () person2.Speak () person3.Speak () If person2.GetSpeakLevel > SpeakLevelEnum.Bad Then Console.WriteLine ("Person2's speaking level is not very bad") End If If person1.CanSpeak Then Console.WriteLine ("Person1 can talk") Else Console.WriteLine ("Person1 can't talk") End If Console.Read () End Sub End Class
Set up a "console project" project in VS2005/2008, delete the default Module1.vb, add a class to the project, copy the above code to this class to overwrite the original content, and you can run debugging.
Learning experience of VB.NET Interface example
With regard to the interface, the learning summary is as follows:
1. Define the interface name. According to convention, the * * letter of the interface name should be named I, such as ISpeak in the example above. The purpose of doing this is to see the name and the meaning, because the English word of the interface is Interface.
2. Since the signatures of members in an interface must be given in the class that implements the interface, they do not need to be preceded by access level modifiers (Public, Privated, etc.)
3. The class implements the interface through the Implements keyword
4. For a class to implement an interface, it must implement all member signatures defined in that interface
5, a class can implement multiple interfaces, the method is in the interface name separated by ",", such as Implements ISpeak,IRun.
This is the end of the article on "sample Analysis of ISpeak Interface in VB.NET". I hope the above content can be helpful 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.
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.