In net, copies are divided into shallow copies and deep copies,
Shallow copy: Creates a new object, and then copies the current object's non-static fields to the new object. If the field is a value type, a bitwise copy is performed on the field. If the field is a reference type, the reference is copied but the referenced object is not copied; Therefore, the original object and its copy refer to the same object (referencing MSDN), which is simply the MemberwiseClone method of the object class.
Deep copy: Creates a new object that contains values and references that are new objects, that is, a complete copy of everything on that object. Ms does not provide an implementation in this way, or simply does not provide, because there are many factors to restrict. It does, however, provide a few classes, such as the Copy method for a DataTable ....
"Cottage culture", has now become a popular word, "mobile phone", "Shanzhai version of the Star", even the "Spring Festival Gala" will be a cottage up ...!
Since the real environment has so many "cottage", that in the context of the program, we need more! The Shanzhai in the program world is a copy of the Object! Ms only gave us a copy of the surface, let us take the "cottage" to the end!
When we want to use the copy, paste, or undo ... These actions, often need to use a copy of the object to operate, so you need to do deep copy (WindowsForm development, this situation is particularly much), but the trouble is here: we can implement ICloneable interface, Then write the Clone method to achieve our goal, but if the relationship between the objects are more, the object of the property is more, then the method of cloning each class ... It's scary! This requires a lot of development time, why don't we get a more common method?!
Well, the way out, in fact, is to do a base class, which has a common copy method, each want to go deep copy of the class to inherit it.