How to Clone Objects

后端 未结 13 1256
北海茫月
北海茫月 2020-11-30 04:36

When I do the following.. anything done to Person b modifies Person a (I thought doing this would clone Person b from Person a). I also have NO idea if changing Person a wil

13条回答
  •  佛祖请我去吃肉
    2020-11-30 05:07

    You could do it like this:

    var jss = new JavaScriptSerializer();
    var b = jss.Deserialize(jss.Serialize(a));
    

    For deep cloning you may want to take a look at this answer: https://stackoverflow.com/a/78612/550975

提交回复
热议问题