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

Why the VB.NET module is not available in languages such as C #

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

Editor to share with you why the VB.NET module is not in C# and other languages, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

First of all, this is a historical reason. Earlier VB languages had the concept of modules and class modules. The so-called module generally stores some common methods (Sub) or functions (Function), and the class module is equivalent to what we often call the concept of class. The following picture is taken from the VBA of Excel, and there is a similar design in VB6.

Second, there are some new things about the VB.NET module.

There can be methods directly in the VB.NET module, and these methods are automatically static (or shared-- the keyword in VB.NET is Shared). These methods can be called directly, so Module cannot be instantiated and there is no need to instantiate them.

The module cannot inherit or implement the interface

There can be classes in the module, but this class does not really need to be referenced by the module as a prefix. So the concept of module is a little virtual.

Modules can be organized into namespaces, because the module is actually virtual, so its methods can also be called directly from the outer namespace.

Here's an example. Note that the code here is written for demonstration purposes only and does not have any specific meaning.

Can be encapsulated in namespaces, which is a better practice

Namespace Xizhang

''

< summary>

The module cannot inherit and cannot implement the interface

''

< /summary>

''

< remarks>

< /remarks>

Module Module1

''

< summary>

The methods in the module are all static

There is no need to instantiate, and there is no way to instantiate

''

< /summary>

''

< remarks>

< /remarks>

Sub Main ()

Dim c As New class1

C.Name = "chenxizhang"

Console.WriteLine (c.Name)

Console.WriteLine (c.GetClassName ())

Console.Read ()

End Sub

''

< summary>

The type can be placed in the module, but the main practical significance is

Classified storage only, put in the module does not affect the external reference of this type.

For example, we don't necessarily need to use Xizhang.Module1.Class1

Instead, it can be referenced directly through Xizhang.Class1.

''

< /summary>

''

< remarks>

< /remarks>

Public Class class1: Implements IComparable

''

< summary>

The''type can inherit a base class and can implement one or more interfaces

''

< /summary>

''

< remarks>

< /remarks>

Private _ name As String

Public Property Name () As String

Get

Return _ name

End Get

Set (ByVal value As String)

_ name = value

End Set

End Property

Public Function GetClassName () As String

Return Me.GetType () .ToString ()

End Function

Public Function CompareTo (ByVal obj As

Object) As Integer Implements System.

IComparable.CompareTo

Return 1

End Function

End Class

End Module

End Namespace

The above is all the content of the article "Why the VB.NET module is not available in languages such as C #". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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