Adds the value of an expression to the value of a variable and assigns the result to the variable. Also concatenates a String expression to a String variable and assigns the result to the variable.
variable += expression
- Required. Any numeric or String variable.
- Required. Any numeric or String expression.
This statement will implicitly perform widening but not narrowing conversions if the compilation environment is enforcing strict semantics. For details on these conversions, see Widening and Narrowing Conversions. If permissive semantics are allowed, the operator will implicitly perform a variety of string and numeric conversions. These conversions are identical to the conversions described for the + operator. For details on how these conversions are performed, see + Operator. For more information on strict and permissive semantics, see Option Strict Statement.
These examples use the += operator to combine the value of one variable with another. In the first example, += is used with numeric variables to add one value to another. In the second example, += is used with String variables to concatenate one value with another. In both cases, the result is assigned to the first variable.
Dim var1 As Integer = 10 Dim var2 As Integer = 3 var1 += var2 ' The value of var1 is now 13. ' This example uses string variables. Dim var1 As String = "10" Dim var2 As String = "3" var1 += var2 ' The value of var1 is now "103".