Compound Arithmetic Assignment Operators - CSharp Language Basics

CSharp examples for Language Basics:Operator

Introduction

Operator DescriptionNoncompound Equivalent
+=x += 4 x = x + 4
-= x -= 4 x = x ? 4
*=x *= 4 x = x * 4
/=x /= 4 x = x / 4
%=x %= 4 x = x % 4

For example, if you want to increase a value by 5, you use the following:

x = x + 5;

Or, you can use the compound operator:

x += 5;

Related Tutorials