C # shortest copy and deep copy

Source: Internet
Author: User

light copy :

If the Members in the array are of the Value Type ( for example, : int, float, double, byte and so on ), the value is completely copied to the target array. , for reference type ( for example, user-defined type : class
Student, class people, or the class type in the class library : arraylist ), copying a reference to the target array.

Sometimes the text is not as goodCodeEasy to understand.However, the Diagram may be easier to understand.,View:

Assume that an array of student classes is created.Student [],Then, copy it to another student array.Student1 []Medium

It is easy to see that the so-called shallow copy applies to the reference type.,Just copy reference.Modifying the memory value through one array affects the reference of another array to memory objects..

The copyto and clone functions in the array class belong to the shortest copy.


deep copy completely creates new objects . Create a new object for all objects in the original array . modifications to the new array do not affect the values or objects in the original array.

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.