Constructors

The System.Text.StringBuilder class can be used to build complex strings. The StringBuilder class has a number of constructors that can be viewed on the MSDN class library, as shown in the following screenshot:

 

PowerShell is also able to show the list of constructors. However, PowerShell cannot show the descriptive text. Still, this may be useful as a reminder if the general functionality is already known. In PowerShell 5.0, the following syntax may be used to list the constructors:

PS> [System.Text.StringBuilder]::new

OverloadDefinitions

-------------------
System.Text.StringBuilder new()
System.Text.StringBuilder new(int capacity)
System.Text.StringBuilder new(string value)
System.Text.StringBuilder new(string value, int capacity)
System.Text.StringBuilder new(string value, int startIndex, int length, int capacity)
System.Text.StringBuilder new(int capacity, int maxCapacity)

For older versions of PowerShell, a longer, less descriptive alternative is available:

PS> [System.Text.StringBuilder].GetConstructors() | ForEach-Object ToString
Void .ctor()
Void .ctor(Int32)
Void .ctor(System.String)
Void .ctor(System.String, Int32)
Void .ctor(System.String, Int32, Int32, Int32)
Void .ctor(Int32, Int32)

Both MSDN and PowerShell show that there are six possible constructors for StringBuilder. Both show that the first of those does not expect any arguments.

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

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