-2

What does it mean "+=".

I have a code here:

static void Main(string[] args)
    {
        int[] n = { 1, 2, 2 };
        int sum = 0;
        foreach (int a in n)
        {
            int b = a * a;
            sum += b;
        }
        Console.WriteLine(sum);
    }

And there is "sum += b;" and I have no idea what does this symbol means...

VaxiZ
  • 33
  • 1
  • 4
  • 2
    `sum += b` stands for `sum = sum + b` – Dmitry Bychenko Jan 31 '22 at 19:37
  • 1
    https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/addition-operator – 41686d6564 stands w. Palestine Jan 31 '22 at 19:38
  • 1
    You can take a look at the C# documentation about [Operators here](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/) and specifically [+ and += here](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/addition-operator) – Xerillio Jan 31 '22 at 19:38
  • 2
    That is basic so I would suggest taking some time to learn a bit more of the language before diving in and trying to write code. – Sorceri Jan 31 '22 at 19:38

2 Answers2

1

its equivalent to :

sum = sum + b;
Amjad S.
  • 1,071
  • 1
  • 2
  • 11
1

It's not a symbol, it's an operator. It's a shorthand operator:

sum += b;

is identical to

sum = sum + b;
zmbq
  • 36,789
  • 13
  • 91
  • 160