Static Constructors

A 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 an application domain. The execution of a static constructor is triggered by the first of the following events to occur within an application domain:

Example

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:

Classes