February 2019
Intermediate to advanced
626 pages
15h 51m
English
The properties defined in a class may define a .NET type and may have a default value if required. The following class has a single property with the String type:
class MyClass { [String]$Property = 'Value'}
PowerShell automatically adds hidden get and set methods used to access the property, these cannot be overridden or changed at this time (within the class itself).
The get and set methods may be viewed using Get-Member with the Force parameter:
[MyClass]::new() | Get-Member get_*, set_* -Force TypeName: MyClassName MemberType Definition---- ---------- ----------get_Property Method string get_Property()set_Property Method void set_Property(string )
The property itself may be accessed on an instance of the class:
$instance = ...
Read now
Unlock full access