简体   繁体   中英

What's the best way to initialize shared members in a class in VB.NET?

I was looking on the Internet to see if there were any good examples on how to initialize shared members within a class while still initializing instance variables. I did find an expression that might fit to the answer:

Shared Sub New()
    'Declare shared members
End Sub

But you also have the standard

Sub New()
    'Declare instance members
End Sub

How do I initialize both instance and shared members without re-initializing the shared members every time an object is created from a class?

Shared Sub New (也称为类型构造函数)对每种类型(即在 AppDomain 内)仅执行一次,因此不会对每个实例重复其中的任何成员初始化。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM