shallow copy and deep copy

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

any body please help me ,Please explain what is a shallow copy and what is a
deep copy?
 
Hi,

you could look for this question in this forum itself for
a couple of days back.

anyway, for your benefit, here's the snippet

A Shallow copy create a new reference to the same object,
whether a deep
copy create a new reference to a new object, I think that
it will better
explained with a graphic, I will do something in paint to
better explain it

A shallow copy creates a new instance of the same type as
the original
object, and then copies the non-static 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

Irfan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top