korean44 wrote:
tbResult.Text += "A";
First - properties are not like variables, so this gets expanded into:
tbResult.Text = tbResult.Text + "A";
tbResult.Text += SomeFunc();
Again:
tbResult.Text = tbResult.Text + SomeFunc();
You should see here that the addition of 'B' to tbResult.Text inside
SomeFunc will be discarded, because C# evaluates expressions from left
to right.
For example, ECMA 334, 8.5:
"Except for the assignment operators, all binary operators are
left-associative, meaning that operations are performed from left to
right. For example, x + y + z is evaluated as (x + y) + z."
I've never met such a result in C++ brefore... I'm very confusing...
You could have - the equivalent in C++ is undefined behaviour. The order
of evaluation of values in an expression in C++ isn't defined.
For example, see clause 5.17 (expr.ass) paragraph 7 of ISO 14882(1998):
"The behavior of an expression of the form E1 op= E2 is equivalent to E1
= E1 op E2 except that E1 is evaluated only once."
And clause 5 (expr) paragraph 4:
"Except where noted, the order of evaluation of operands of individual
operators and subexpressions of individual expressions, and the order in
which side effects take place, is unspecified."
There is no such note for additive expressions, so this means that the
function call could happen before or after the read of E1, so E1 could
have the before or after value.
-- Barry
--
http://barrkel.blogspot.com/