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 books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.