Assignment Operators
What Are Assignment Operators in C#?
C# assignment operators assign values to variables along with the assignment; in some cases, these operators perform mathematical operators.
List of C# Assignment Operators
There are following assignment operators supported by C# −
| Operator | Symbol | Description | Example |
| Simple Assignment | = | Simple assignment operator, Assigns values from right side operands to left side operand | C = A + B assigns value of A + B into C |
| Add and Assign | += | Add AND assignment operator, It adds right operand to the left operand and assign the result to left operand | C += A is equivalent to C = C + A |
| Subtract and Assign | -= | Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result to left operand | C -= A is equivalent to C = C - A |
| Multiply and Assign | *= | Multiply AND assignment operator, It multiplies right operand with the left operand and assign the result to left operand | C *= A is equivalent to C = C * A |
| Divide and Assign | /= | Divide AND assignment operator, It divides left operand with the right operand and assign the result to left operand | C /= A is equivalent to C = C / A |
| Modulus and Assign | %= | Modulus AND assignment operator, It takes modulus using two operands and assign the result to left operand | C %= A is equivalent to C = C % A |
| Left Shift and Assign | <<= | Left shift AND assignment operator | C <<= 2 is same as C = C << 2 |
| Right Shift and Assign | >>= | Right shift AND assignment operator | C >>= 2 is same as C = C >> 2 |
| Bitwise AND and Assign | &= | Bitwise AND assignment operator | C &= 2 is same as C = C & 2 |
| Bitwise XOR and Assign | ^= | bitwise exclusive OR and assignment operator | C ^= 2 is same as C = C ^ 2 |
| Bitwise OR and Assign | |= | bitwise inclusive OR and assignment operator | C |= 2 is same as C = C | 2 |