Static constructor is a class member that implements the actions required to initialize a class.
static-constructor-declaration:
attributesopt static-constructor-modifiers
Constructor constructor-name () ; method-localsopt
Begin method-body End Constructor constructor-nameopt ;
static-constructor-modifiers:
Shared
Static constructors are not inherited by derived classes and cannot be called explicitly. A static constructor is executed only once for each application domain. A static constructor is executed by the first occurring of the following events within an application domain:
A class instance is created.
Any of the static members of the class are referenced.
Class UserObject
Public Shared i: integer;
Public Shared s: string;
//This constructor is invoked when static fields are referenced
//or when an object instance is created
Shared Constructor Create();
Begin
i := integer.MinValue;
s := "Default";
End Constructor;
End Class;
See also: