Are value types immutable by definition?

后端 未结 12 1507
陌清茗
陌清茗 2020-12-04 09:18

I frequently read that structs should be immutable - aren\'t they by definition?

Do you consider int to be immutable?

int i         


        
12条回答
  •  既然无缘
    2020-12-04 09:31

    Mutability and value types are two separate things.

    Defining a type as a value type, indicates that the runtime will copy the values instead of a reference to the runtime. Mutability, on the other hand, depends on the implementation, and each class can implement it as it wants.

提交回复
热议问题