Post-increment within a self-assignment

前端 未结 6 1538
南方客
南方客 2020-12-02 22:30

I understand the differences between i++ and ++i, but I\'m not quite sure why I\'m getting the results below:

static void Main(string[] args)
{
    int c = 4         


        
6条回答
  •  悲&欢浪女
    2020-12-02 23:05

    The expression on the right-hand-side of an assignment is evaluated completely, then the assignment is performed.

       c = c++;
    

    Is the same as

       // Right hand side is calculated first.
       _tmp = c;
       c = c + 1;
    
       // Then the assignment is performed
       c = _tmp;
    

提交回复
热议问题