Assignments Operators

English:

Try it yourself to think about one solution to add +1 value to a variable without losing its current value.
Do you know how does do that?
Simple: add the self value from variable and then plus 1:

int variable = variable + 1;

"variable" receives its current value and plus one.
If "variable" equals 5, now it is 6.
As the same way, you are able to do this operation with subtraction and other arithmetics operations:

int a = a - 5;
int b = b * 20;
int c = c / b;
int d = d % 2;

In C# we have assignments operators besides of "=", to write the operations above, but being a better syntax, check out below:

int number += 10; // As the same that: number = number + 10

int a -= 20; // Same as: a = a - 20
int b *= 5; // b = b * 5
int c /= 40; // c = c / 40
int d %= 7; // d = d % 7

Português-BR:

Tente você mesmo pensar em uma solução para adicionar +1 ao valor de uma variável sem perder o valor atual.
Você sabe como faz isso?
Simples: adicione o valor próprio da variável e depois acrescente 1:

int variavel = variavel + 1;

"variavel" recebe seu valor atual e mais um.
Se "variavel" for igual a 5, agora é 6.
Da mesma forma, você pode fazer esta operação com subtração e outras operações aritméticas:

int a = a - 5;
int b = b * 20;
int c = c / b;
int d = d% 2;

Em C #, temos operadores de atribuições além de "=", para escrever as operações acima, mas sendo uma sintaxe melhor, confira abaixo:

int  number + = 10; // Da mesma forma que: number = number + 10

int a - = 20; // Igual: a = a - 20
int b * = 5; // b = b * 5
int c / = 40; // c = c / 40
int d% = 7; // d = d% 7

Comentários

Postagens mais visitadas deste blog

Boolean type

Increment and decrement operations