what is boxing? what is unboxing? what is deep copy & shallow copy?

Converting the value type into reference type is call boxing.

Converting the reference type into value type is call unboxing.

When an object of value type is assigned with another, the data itself is copied from one object to another. Suppose there are two integer variables, count1 and count2. Further suppose that count1 contains the value 5 and that count2 is assigned the value of count1.
count1 = 5;
count2 = count1;
Both count1 and count2 now contain their own copies of the data, in this case, the value 5. They are independent. If count1 is now assigned the value 6, count2 will still contain the value 5. This type of copy is referred to as a deep copy. The value itself is copied.

If count1 is now assigned the value 6, count2 will still contain the value 5. This type of copy is referred to as a deep copy.
For reference types copies work differently. Remember that a reference type consists of two parts: the data on the heap and the address of the data stored in the reference variable itself on the stack. When one reference variable is assigned to another, the address stored in the first is copied to the second. They both then refer to the same data content on the heap. This is referred to as a shallow copy.

 

Shashi Ray

Ebook Download
View all
Learn
View all