Shared Constructors

Classes can implement shared constructors, as shown in the following code:

'Private visibilityShared Sub New()    'Initialization of shared    'members    sharedField = 10End Sub

Shared constructors are particularly useful for initializing shared members or for loading data that is common to all instances of a class. A shared constructor is invoked immediately before the normal constructor that creates a new instance of the class. With that said, the following code is appropriate and accepted by the compiler:

Shared Sub New()    'Initialization of shared    'members    sharedField = 10End SubSub New()End Sub

Another important thing to take care of is that shared constructors ...

Get Visual Basic 2015 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.