Shallow Copy and Deep Copy

Difference between Shallow Copy and Deep Copy

Shallow Copy


Shallow Copy
Shallow Copy

Console.Writeline("oCloneMeTarget - {0}", oCloneMeTarget.oShallowCopy.iValue);  // Output: oCloneMeTarget – 6


Deep Copy


Deep Copy
Deep Copy

Console.Writeline("oCloneMeTarget - {0}", oCloneMeTarget.oDeepCopy.iValue);  // Output: oCloneMeTarget – 10

This time, the contained objects are independent.


Difference between Shallow Copy and Deep Copy, real world scenarios and live code example of shallow copy and deep copy, use of shallow copy and deep copy