Tuesday, 20 November 2012

Difference Between Shallow Copy & Deep Copy

Shallow Copy:  In Shallow copy, the Second object is attached to same memory block. hence any change in either will reflect in Second one. This is faster than deep copy.

Deep Copy:  In Deep copy, Structure and data is copied and both behave as two objects.

Example :  System.Array.CopyTo() and System.Array.Clone()

System.Array.Clone() creates a shallow copy

while System.Array.CopyTo()  creates a deep copy

No comments:

Post a Comment