Skip to content
Justice Tech School

C# Assignment Operators

x += 3 means x = x + 3. The same works for -=, *=, /= and %=. ??= assigns only when the value is null.

Example
int x = 10;
x += 5; x *= 2;
string? s = null;
s ??= "default";
Console.WriteLine($"{x} {s}");

Exercise

Add 5 to x.

x  5;

Quiz Test

What does x *= 2 do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.