加法赋值运算符。
备注
使用 += 赋值运算符的表达式,例如
![]() | |
---|---|
x += y |
等效于
![]() | |
---|---|
x = x + y |
不同的是 x
只计算一次。+ 运算符的含义取决于 x
和 y
的类型(例如,对于数值操作数,其含义为相加;对于字符串操作数,其含义为串联)。
示例
![]() | |
---|---|
// cs_operator_addition_assignment.cs using System; class MainClass { static void Main() { int a = 5; a += 6; Console.WriteLine(a); string s = "Micro"; s += "soft"; Console.WriteLine(s); } } |
输出
11 Microsoft |
请参见
