Skip to content

Rule request: Avoid using the Assignment by Addition Operator (+=) to build a string #1935

Open
@iRon7

Description

@iRon7

Summary of the new feature

Strings are immutable. Each addition to the string actually creates a new string big enough to hold the contents of both the left and right operands, then copies the elements of both operands into the new string. For small strings, this overhead may not matter. For large strings, this can affect performance and memory consumption.
This will create more awareness of the possible performance impact of using the Assignment by Addition Operator (+= ), see also:

Proposed technical implementation details (optional)

See (PowerShell based) prototype AvoidPlusEqualsToBuildStrings at: https://github.com/iRon7/PSRules

What is the latest version of PSScriptAnalyzer at the point of writing

1.21.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions