Duplicate Object and working with Duplicate without changing Original

后端 未结 8 632
逝去的感伤
逝去的感伤 2020-12-08 14:02

Assuming I have an Object ItemVO in which there a bunch of properties already assigned. eg:

ItemVO originalItemVO = new ItemVO();
originalItemVO.ItemId = 1;         


        
8条回答
  •  攒了一身酷
    2020-12-08 14:21

    By Default objects are reference type.

    Assign the one object to another object its means that you just refer the address of the object.Any changes in any object it will reflect in both.

    To solve this problem you should have initialize the object using "new" keyword, then add this object value in the first object.

提交回复
热议问题