Write Your First Code Using C# - Perform Basic Operations on Numbers in C#

Tell us what’s happening:

Describe your issue in detail here.

I’m having trouble understanding how the position of increment and decrement operators. Specifically, this example:

int value = 1;
value++;
Console.WriteLine("First: " + value);
Console.WriteLine($"Second: {value++}");
Console.WriteLine("Third: " + value);
Console.WriteLine("Fourth: " + (++value));

I’m unsure of the difference between having the + or - symbols in front of the variable and after the variable and what difference it makes to the final result.

Any help is appreciated!

Challenge Information:

Write Your First Code Using C# - Perform Basic Operations on Numbers in C#

Don’t forget about order of operations.

value++:

  • gets the current number stored in value, currently 2.
  • add the current value to the string.
  • adds 1 (++ means add 1) to the number, now 3.
  • store that number in value, value is now 3, not 2.

++value:

  • gets the current number stored in value, currently 3.
  • adds 1 (++ means add 1) to the number, now 4.
  • store that number in value, value is now 4, not 3.
  • add the number in value to the string.
2 Likes