Introduction
In this blog, we will write a C# program for the incremental and decremental mathematical operators.
Increment Operator
The increment operator increases a value by one and it's just simply two plus operators together. If the incremental operators is used before the operand it returns the value after the increase .
If int a equals five then plus plus a returns six.
Now if the incremental operator is used after the operand it actually returns the value before the increase. So if int a equals five a plus plus returns five. This can sound very confusing but understand that both a plus plus a would both return six on the line after the increase. This will make a lot of sense once we see a demonstration of the incremental operand.
- ++ : Increment Operator - Increases value by 1
- if used before the operand it returns the value after the increase
- int a = 5;++ a returns 6.
- If used after the operand it returns the value before the increase
- int a = 5 ; a++ returns 5.
- Both a++ and ++a return 6 on the line after the incease
Decrement Operator
The decrement operator subtracts the value by one and it's simply two subtraction operators together, much like the incremental operator if the decrement operator is used before the operand it returns the value after the decrease.
If int a equals 5 then minus minus a returns four. It the decrement operator is used after the operand then it returns the value before the decrease so if int a equal 5 a minus minus also returns 5 but once again both a minus minus and minus minus a return 4 on the line after the decrease now
- -- : Decrement Operator - Decreases value by 1
- if used before the operand it returns the value after the decrease
- int a = 5;-- a returns 4.
- If used after the operand it returns the value before the decrease
- int a = 5 ; a-- returns 5.
- Both a-- and --a return 64on the line after the decrease
Increment and Decrement Operators in C# Code
This code sample shows you how to do it in C# Code.



Join the conversation! Your thoughts help the community grow.