How it works...
In .NET (and .NET Core), a string is immutable and effectively read-only once it is created. This was done for improved performance. If you extend these immutable strings with + and +=, however, the opposite happens. Because the string has to be created from scratch with the new value, this operation will get very costly.
The StringBuilder class is specialized precisely for its name: building strings. It can do this very well and, of course, can be used in PowerShell Core without problems. In this recipe, you also saw the join operator. You might not have seen the unary join operation before, which simply concatenates strings. It is even faster than StringBuilder, but not nearly as flexible. This recipe is, again, a matter ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access