Is modifying a value type from within a using statement undefined behavior?

后端 未结 4 1045
予麋鹿
予麋鹿 2021-02-08 07:08

This one\'s really an offshoot of this question, but I think it deserves its own answer.

According to section 15.13 of the ECMA-334 (on the using statement,

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-08 07:53

    I would read the standard in such a way that

    using( var m = new Mutable() )
    {
       m = new Mutable();
    }
    

    is forbidden - with reason that seem obious. Why for the struct Mutable it is not allowed beats me. Because for a class the code is legal and compiles fine...(object type i know..)

    Also I do not see a reason why changing the contents of the value type does endanger the RA. Someone care to explain?

    Maybe someone doing the syntx checking just misread the standard ;-)

    Mario

提交回复
热议问题