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

I looked on the Internet to find out if there are good examples of how to initialize shared members inside a class when initializing instance variables. I found an expression that is suitable for the answer:

Shared Sub New() 'Declare shared members End Sub 

But you also have a standard

 Sub New() 'Declare instance members End Sub 

How to initialize both instances and shared members without reinitializing shared members each time an object is created from a class?

+6
source share
1 answer

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

+12
source

Source: https://habr.com/ru/post/895704/


All Articles