0

Under which circumstances are either prefix or postfix preferable and what does each of them mean, I know that prefix increments it then àssigns the value and postfix evaluates the expression then increments it but can someone actually explain the meaning of that also what does incrementing actually mean?

  • 1
    Are you referring to specific operators? – Stefan Sep 02 '20 at 12:48
  • do you mean this? https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/arithmetic-operators#increment-operator- – cad Sep 02 '20 at 12:51

1 Answers1

3
int i = 1;
int j = i++;
//i = 2; j = 1 as the incrementation performed after the assignment
//{ int j = i++; } equals to { int j = i; i = i + 1; }

i = 1;
j = ++i;
//i = 2; j = 2 as the incrementation performed before the assignment
//{ j = ++i; } equals to { i = i + 1; j = i; }
Roman Ryzhiy
  • 1,540
  • 8
  • 5