February 2019
Intermediate to advanced
626 pages
15h 51m
English
Arguments for constructors can be passed in as an array. Each of the following may be used to create an instance of a StringBuilder object:
$params = @{ TypeName = 'System.Text.StringBuilder' ArgumentList = 'Initial value', 50}$stringBuilder = New-Object @params$stringBuilder = New-Object System.Text.StringBuilder($argumentList)
Attempting to pass in a list of arguments using the new method will produce a different result; the initial string will be filled with both values:
PS> $argumentList = 'Initial value', 50PS> $stringBuilder = [System.Text.StringBuilder]::new($argumentList)PS> Write-Host $stringBuilder.ToString() -ForegroundColor GreenPS> $stringBuilderInitial value 50Capacity MaxCapacity Length-------- ----------- ...
Read now
Unlock full access