February 2019
Intermediate to advanced
626 pages
15h 51m
English
A constructor is executed when either New-Object or ::new() is used to create an instance of a class. If an explicit constructor is not declared, an implicit constructor is created for the class. The implicit or default constructor does not require arguments:
PS> [MyClass]::newOverloadDefinitions-------------------MyClass new()
An explicit constructor may be created to handle more complex instantiation scenarios. The constructor must use the same name as the class. The following constructor makes use of the $this reserved variable to access other members of the class:
class MyClass { [String]$Property MyClass() { $this.Property = 'Hello world' }}
Constructors may be overloaded, that is, more than one constructor might be declared. ...
Read now
Unlock full access