February 2019
Intermediate to advanced
626 pages
15h 51m
English
Constructor chaining avoids the need to repeat the work a single constructor performs. Overloaded methods can be used to simulate constructor-chaining within a class.
In C#, constructor-chaining allows one constructor to call another using the this keyword. This would be similar to the use of the base keyword when invoking an inherited constructor. This form of chaining is not possible in PowerShell; a workaround is required.
Each constructor is given an associated method; the methods call each other depending on the arguments supplied:
class MyClass { [String]$FirstProperty [String]$SecondProperty MyClass() { $this.Initialize() } MyClass([String]$First) { $this.Initialize($First) } MyClass([String]$First, [String]$Second) ...Read now
Unlock full access