VB.NET中的静态构造函数

VB.NET中的静态构造函数

问题描述:

如何在VB.NET中创建静态构造函数?

How can we create a Static constructor in VB.NET?

当程序集自身加载时,将初始化并调用类的静态构造函数. /> 在VB.NET模块中等效于静态(共享)类.
添加模块
A Static Constructor of a class gets initialised and invoked when the assembly loads itself.
in VB.NET modules are equivalent of a static (shared) Class.
add a module
'in a Module:
Sub New()
'your code goes here
End Sub


可能读取文档(共享的构造方法 [
Class ExplicitConstructor

    Shared Sub New()
        _message = "Hello World"
    End Sub

    Public Shared ReadOnly Property Message() As String
        Get
            Return _message
        End Get
    End Property

    Private Shared _message As String

End Class