Used to declare a special type of procedure that resembles a function and initializes the type. Constructors can either initialize an instance or the static data members. Like functions, constructors can take any set of parameters and keywords needed. Unlike functions, instance constructors always return a copy of the constructed type instance. Static constructors always return nothing. Furthermore, constructors can only be called with help from the new keyword. Instance constructors can be public, protected, or private. Private instance constructors can only be called by a static method or property in the same class. Instance constructors can be overloaded as needed. Static constructors never take any parameters.
(\public\ | \protected\ | \private\) \constructor\ /identifier/ /DeclarationSequence/ ' Initialize the class
/DeclarationSequence/ must be as described in Declaration Sequences.
\static\ \constructor\ ' Initialize the static data members
As long as the type isn't abstract or static, you can instantiate an instance with the syntax below which will call constructors for the type as needed.
\new\ /TypeName/ /ParameterList/
/TypeName/ must be the name of the type being instantiated and /ParameterList/ must be the parameters needed by that constructor along with any required keywords. Please note this sample doesn't show what you do with the new instance. You might also need to put the parameter list into parentheses depending on what else you are doing. If you put the expression from the new keyword to through the parameter list, but no farther, you can use the . operator to access the data members, methods, and properties in the new instance as shown below:
(new String "Test ").TrimRight
(The String type was only used for that sample as no further declarations were needed for the sample.)
Wiki: Attributes
Wiki: Keywords
Wiki: Type casts
Wiki: keywords-abstract
Wiki: keywords-creator
Wiki: keywords-enum
Wiki: keywords-function
Wiki: keywords-new
Wiki: keywords-throw
Wiki: operators-brackets