Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

+=: practical reference

+=: practical reference: += computes addition and assigns the converted result back to its left operand.

Version: C# language; verified against C# 14 reference

Syntax

left += right

+= computes addition and assigns the converted result back to its left operand.

Use it to accumulate or update a variable without repeating its name.

The left operand is evaluated once; for an event, += subscribes a handler.

Overflow and conversion follow the left-side type and the checked context.

The complete program actually uses +=; its exact expected stdout is 5.

Examples

using System;
using System.Linq;
using System.Threading.Tasks;

var value = 2; value += 3; Console.WriteLine(value);

Result

5

The complete program actually uses `+=`; its exact expected stdout is `5`.

Sources