I have two questions about this code ...
Why does line 10 start saving the current value. For instance,
int a = 7
(a += 4)This 11wraps to the next line of code (a -= 4), now does it 7. Instead of just using this initial declaration for a variable athat is 7. Why am I not getting 3? Is the =statement a +=change to what I originally declared at the beginning of the code? Does the avalue remain 7in memory, or are these statements changing?
In the last expression MessageBox.Show(). I increase aby 1using a++. However, I get the same value as the previous one MessageBox.Show(). Why hasn't it increased?
This is the code:
private void button1_Click(object sender, EventArgs e)
{
int a = 7;
int b = 3;
MessageBox.Show((a + b).ToString(), "a+b");
MessageBox.Show((a - b).ToString(), "a-b");
MessageBox.Show((a * b).ToString(), "a*b");
MessageBox.Show((a / b).ToString(), "a/b");
MessageBox.Show((a += 4).ToString(), "a+=4");
MessageBox.Show((a -= 4).ToString(), "a-=4");
MessageBox.Show((a *= 4).ToString(), "a*=4");
MessageBox.Show(a++.ToString(), "a++");
}
source
share