Defining Shared Constructors

Visual Basic .NET implements constructors as Sub New. By prefixing a constructor with the Shared modifier, you can implement a shared constructor.

Shared constructors are used to initialize shared members to their default values implicitly and can be implemented to perform additional initialization of shared members. Shared constructors are run implicitly after your program loads and are guaranteed to run only once before any instances of a type containing a shared constructor are created and before any shared members are accessed. Shared constructors are also run before derived types are used.

You can't overload shared members. Shared constructors cannot call other constructors, cannot take parameters, and cannot ...

Get Visual Basic® .NET Unleashed now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.