2017-03-21 2 views
0

基本的に私は静的共有メンバーを持つクラスを持っています。その静的共有メンバーを開始するために一度実行するコードが必要です。クラスのためにvb.netで一度コードを実行するには?

Class algorithm 
    Public name As String 
    Public lowPriceatNiceHash As Double 
    Public highPriceatNiceHash As Double 
    Public fixedPriceatNicehash As Double 

    Shared dictOfAlgorithm As Generic.Dictionary(Of String, algorithm) 
End Class 

dictOfAlgorithmディクショナリは、クラスの使用開始時に新しい空のディクショナリに設定する必要があります。 1回だけ。

+0

https://msdn.microsoft.com/en-us/library/z2cty7t8.aspxを? –

答えて

1

その宣言どこにそれを初期化します。

Class ... 

    Public Shared dictOfAlgorithm As Generic.Dictionary(Of String, algorithm) = New Generic.Dictionary(Of String, algorithm) 

End Class 

または.cctor使用:

Class ... 

    '' Shared .ctor, called once the first time the class is accessed. 
    Shared Sub New() 
     dictOfAlgorithm = New Generic.Dictionary(Of String, algorithm) 
    End Sub 

    Public Shared dictOfAlgorithm As Generic.Dictionary(Of String, algorithm) 

End Class 
+0

cctorとは何ですか?そうです、彼らはそれを持っていると聞いたことがあります。 –

+0

Shared Sub Newを公開することはできますか? –

+0

@ F0r3v3r-A-N00b可能ですが、Sub Newはオブジェクトの構築にすぎず、newキーワードを使ってオブジェクトを作成すると実行されます。それは任意のアクセス修飾子を持つことができますが、共有は通常、共有変数を初期化していることを示します。 – Jaxi

関連する問題