"sujith" <sujith (AT) discussions (DOT) microsoft.com> wrote
Quote:
hello can anybody explain diffrence between shaloow copy and deep copy in
c# |
This applies, not just to C#, but to any language that employs "reference
types".
When copying an object, a shallow copy makes copies of the contents of
fields as defined in the class definition. If one or more of the fields is a
reference type (holds the address where the actual data is stored), then it
is the address that is copied. You end up with multiple references to the
same data.
When you write a method to perform a "deep copy", you don't just copy the
addresses stored in reference type fields, you retrieve the actual data and
make a copy of the data at a new location, thus making the new copied object
fully independent of the original object.
--
Peter [MVP Visual Developer]
Jack of all trades, master of none.