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

江枫思渺然 提交于 2019-12-01 14:48:59

问题


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?


回答1:


Shared Sub New (also known as a type constructor) is executed only once for each type (within an AppDomain, that is), so any member initialization in there will not be be repeated for each instance.



来源:https://stackoverflow.com/questions/7166649/whats-the-best-way-to-initialize-shared-members-in-a-class-in-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!