C# standard question

  • Thread starter Thread starter Reginald Blue
  • Start date Start date
R

Reginald Blue

This is purely out of curiosity.

In C and C++, the following statements invoke undefined behavior:

int i = 3;
i = i++;

(for reference:
http://www.eskimo.com/~scs/C-faq/q3.3.html )

Does the C# standard specify the behavior for such constructs? A quick test
reveals that the value assigned to i is 3 which is interesting, but not
particularly revealing.

--
Reginald Blue
"I have always wished that my computer would be as easy to use as my
telephone. My wish has come true. I no longer know how to use my
telephone."
- Bjarne Stroustrup (originator of C++) [quoted at the 2003 International
Conference on Intelligent User Interfaces]
 
Reginald Blue said:
This is purely out of curiosity.

In C and C++, the following statements invoke undefined behavior:

int i = 3;
i = i++;

(for reference:
http://www.eskimo.com/~scs/C-faq/q3.3.html )

Does the C# standard specify the behavior for such constructs?
Yes.

A quick test reveals that the value assigned to i is 3 which is
interesting, but not particularly revealing.

It's fairly simple in C#. The RHS is evaluated and has a value of 3
while incrementing i to 4. The assignment is then performed, setting
the value of i back to 3.
 
Back
Top