+ 1

C# Question

So I did try and look up this on the Q&A but it wouldn't search for it unfortunately. Anyways, I'm trying to learn C# and this question came up in the quiz. int a = 4; int b = 6; b = a++; Console.WriteLine(++b); The answer is 5 from the quiz but I'm rather confused as to how why. Any help would be appreciated!

5th Sep 2017, 2:08 PM
adam brenningemeyer
adam brenningemeyer - avatar
3 Respuestas
+ 4
b is 6 make b = 4(a), THEN add to a write line of b, add 1 before it's used which is 5 these are called increments and decrements. Knowing that you can probably search explanations a lil better. Thank you for searching first
5th Sep 2017, 2:21 PM
Jordan Chapman
Jordan Chapman - avatar
+ 2
yes, sounds about right
5th Sep 2017, 2:36 PM
Jordan Chapman
Jordan Chapman - avatar
+ 1
Awesome! Thank you so much for the help! So just make sure I get it: Even though b = 6, since b = a++ it would replace b = 6 Finally in the Console, since we have ++b, it basically adds the increment before moving on with the expression?
5th Sep 2017, 2:37 PM
adam brenningemeyer
adam brenningemeyer - avatar