开发者

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

开发者 https://www.devze.com 2023-03-30 19:13 出处:网络
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

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()
    'Declar开发者_如何转开发e 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 (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.

0

精彩评论

暂无评论...
验证码 换一张
取 消