2.7 Assignment Operators

Stasoz
2 min readApr 5, 2022

You can check this course on my website.

Assignment operators set the value of the right operand to the left operand. The most basic assignment operator that is found everywhere is =

Here, using the operator = we set the value of the age variable. Also, you can simultaneously assign a value to several variables at once.

= — is right-associative operator, it means that first initializes z, then y, then x. Let’s consider other assignment operators:

  • += — addition assignment; Same as x = x + 5;
  • -= — subtraction assignment; Same as x = x — 4;
  • *= — multiplication assignment; Same as x = x * 3;
  • /= — division assignment; Same as x = x / 2;
  • %= — modulo assignment; Same as x = x % 5;

Of course, C# has more assignment operators, but we’ll look at them later so you know how to use them.

Summary — Operators Precedence and Associativity

Contents

Previous article -> 2.6 Arithmetic Operators

Next article -> 2.8 Comparison Operators

Join to our community in Telegram — https://t.me/itifico

If you want to support me, you can buy me a cup of coffee and I will drink it when I write the next article :)

Donations list:

  1. Dinesh Chintalapudi — 3$
  2. Unknown — 5$
  3. Neisy — 3$
  4. Unknown — 3$

--

--

Stasoz

Full Stack Developer who is inspired by new technologies