Calling constructors

In PowerShell 5.0 and higher, an object instance may be created using the new static method:

$stringBuilder = [System.Text.StringBuilder]::new() 

For earlier versions of PowerShell, the object instance may be created using the following syntax:

$stringBuilder = New-Object System.Text.StringBuilder 

PowerShell has added the static method (discussed later in this chapter); it can be used if required, but it isn't documented on the MSDN page for StringBuilder.

Once an instance of StringBuilder has been created, it can be viewed:

PS> $stringBuilder = New-Object System.Text.StringBuilder
PS> $stringBuilder

Capacity MaxCapacity Length
-------- ----------- ------
16 2147483647 0

The StringBuilder object has a number of other constructors. These are used to adjust the initial state of the instance.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.231.245