C# Reference type assignment VS value type assignment

后端 未结 6 1387
自闭症患者
自闭症患者 2020-12-06 22:27

I understand the theoretical concept that assigning one reference type variable to another, only the reference is copied, not the object. assigning one value type variable t

6条回答
  •  情歌与酒
    2020-12-06 23:18

    To see the difference more clearly, try something like

    joe.Inches = 71;
    bob.Inches = 59;
    ...
    

    // assign joe reference value to bob variable

    bob = joe;
    joe.Inches = 62;
    
    // write bob and joe
    

    And do something similar in the reference-type example.

    You will be able to demonstrate that in the second examples there are two different instances of Height, while in the first example there is only one (shared) instance of Employee.

提交回复
热议问题