Concatenation Assignment (+=) Expression

Summary

Appends a string value to an existing variable, property, or array element.

Syntax

variable += expression

Parameters

variable
The variable, property, or array element to be given a value.
expression
Any legal expression.

Description

For string variables, the += operator computes the string value of the expression on the right, and then appends it to the variable, property, or array element on the left. The expression on the right is evaluated prior to assignment.

The += operator is equivalent to the + operator with the left-hand side being the variable, property, or array element to modify and the right-hand side being the expression to concatenate. Therefore, the following expressions are equivalent:

1
2
x += "foo";    // Equivalent to x = x + "foo"
x = x + "foo"; // Equivalent to x += "foo"

Examples

Basic Usage
1
2
3
4
5
6
import System;
 
string foo = "foo";
Console.log(foo); // "foo"
foo += "bar";
Console.log(foo); // "foobar"

See Also

Share

HTML | BBCode | Direct Link