Cloning objects in C#
- by Alison
I want to do something like...
myObject myObj = GetmyObj()//create and fill a new object
myObject newObj = myObj.Clone();
...and then make changes to the new object that are not reflected in the original object.
I don't often need this functionality so when it's been necessary I've resorted to creating a new object and then copying each property individually but it always leaves me with the feeling that there is a better/more elegant way of handling the situation.
How can I clone/deep copy an object so that the cloned object can be modified without any changes being reflected in the original object?