Wednesday, May 21, 2008

C#: Shallow Copy

In C#, the shallow copy is also referred as memberwise copy.

A shallow copy creates a new instance of the same type as the original object, and then copies the nonstatic fields of the original object. If the field is a value type, a bit-by-bit copy of the field is performed. If the field is a reference type, the reference is copied but the referred object is not; therefore, the reference in the original object and the reference in the clone point to the same object. In contrast, a deep copy of an object duplicates everything directly or indirectly referenced by the fields in the object.

Refer to this article for more details.

http://blogs.msdn.com/brada/archive/2004/05/03/125427.aspx

0 comments: