+ 1
What is the n variable (C# Puzzle)?
You shouldn't use an IDE for an answer. Use your brain. var n = 2; n = n+++ ++n; // n = ? P.S. For any .net framework and any C# versions compiler behavior will be the same.
1 Antwort
+ 2
6
Explanation:
We declared that n is equal to 2,
the next line shall be separated to 4 parts.
n = n+++ ++n;
n+++ is simply n++ and another + of addition between n++ and ++n.
The n++ tells us that n will increase after the entire line is executed.
++n tells us to increase the value of n by 1 right now.
So n = n++ (n stays the same) + ++n (n increased by 1, only this n though) is analogical to
n = 2 + 3;
n = n + 1; (is the n++ in the previous line)
Therefore the answer is 6.