You are on page 1of 3

Difference between Shallow copy and Deep copy

1 of 3

http://net-informations.com/faq/net/shallow-deep-copy.htm

Net-informations.com
AJAX

.Net Framework

Home
C#
Interview Questions

Difference between Shallow


copy and Deep copy

SiteMap | About
VB.NET
About

ASP.NET

Share

An object copy is a process where a data object has


its attributes copied to another object of the same
data type. In .Net Shallow copy and deep copy are
used for copying data between objects.
What is Shallow copy ?

.Net Environment - Interview


Questions
ADO.Net - Interview Questions
Shallow copying is creating a new object and then
copying the non static fields of the current object to
the new 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 original object
and its clone refer to the same object. A shallow
copy of an object is a new object whose instance
variables are identical to the old object. In .Net
shallow copy is done by the object method
MemberwiseClone().
The situations like , if you have an object with values
and you want to create a copy of that object in
another variable from same type, then you can use
shallow copy, all property values which are of value
types will be copied, but if you have a property which
is of reference type then this instance will not be
copied, instead you will have a reference to that
instance only.

.Net Framework - Interview


Questions
.Net General - Interview
Questions

Asp.Net - Interview Questions


Object Oriented Programming Questions
.Net - Frequently Asked Questions
.Net - Interview Questions quick
answers

What is Deep copy ?

26-Dec-16 9:23 PM

Difference between Shallow copy and Deep copy

2 of 3

http://net-informations.com/faq/net/shallow-deep-copy.htm

Pharma Serialization
More Source Code :

Mail to : feedback@net-informations.com
net-informations.com (C) 2016 Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.

Deep copy is creating a new object and then copying


the non-static fields of the current object to the new
object. If a field is a value type, a bit by bit copy of
the field is performed. If a field is a reference type, a
new copy of the referred object is performed. A deep
copy of an object is a new object with entirely new
instance variables, it does not share objects with the
old. While performing Deep Copy the classes to be
cloned must be flagged as [Serializable].
Deep copy is intended to copy all the elements of an
object, which include directly referenced elements of
value type and the indirectly referenced elements of
a reference type that holds a reference to a memory
location that contains data rather than containing the
data itself.
Next : Use of System.Environment Class

Difference between a Debug and Release build


Difference between normal DLL and .Net DLL
What is an Interface
Difference between Abstract Class and Interface
Difference between a thread and a process
What is .Net Delegates
Differences between a control and a component
Differences between Stack and Heap
What is .Net Reflection
Globalization and Localization
What is .Net serialization
Difference between web service and .net remoting
Difference between managed and unmanaged code

26-Dec-16 9:23 PM

Difference between Shallow copy and Deep copy

3 of 3

http://net-informations.com/faq/net/shallow-deep-copy.htm

Use of System.Environment Class

26-Dec-16 9:23 PM

You might also like