Tag Archives: copy object

Clone lists and arrays of objects in C#

This is the last post I’ll write about clones, at least for a while. Some collection classes can already make clones. For example, an array can clone itself, although the result is always a shallow clone. This example shows how … Continue reading

Posted in algorithms, OOP, syntax | Tagged , , , , , , , , , , , , , | 1 Comment

Clone serializable objects in C#

If a class is serializable, then you can create a deep clone of an object from that class by serializing it and the deserializing it. This example uses the following code to define a generic extension method that clones objects … Continue reading

Posted in algorithms, OOP, syntax | Tagged , , , , , , , , , , , , , | 5 Comments

Use MemberwiseClone the ICloneable interface in C#

The example Clone objects in C# explains how to give a class a Clone method that makes copies of its objects. This example makes two changes: it implements the ICloneable interface and it uses MemberwiseClone to simplify the cloning code. … Continue reading

Posted in algorithms, OOP, syntax | Tagged , , , , , , , , , , , , , , , | Leave a comment

Clone objects in C#

A clone of an object is a copy of that object. There are two kinds of clones: shallow and deep. A shallow clone shares all of the same values as the original object, even if some of those values are … Continue reading

Posted in algorithms, OOP, syntax | Tagged , , , , , , , , , , , , | Leave a comment