Full conversion of "object" to "Cottage object"

Source: Internet
Author: User
Tags shallow copy

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.