Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / December 2004

Tip: Looking for answers? Try searching our database.

Cloning

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
AVL - 14 Dec 2004 09:27 GMT
Hi,
     I've  a query in cloning. How cloning is different from creating a new
instance of an object.? I suppose cloning also creates a new object and
copies the exisitng object's data. Where and when should use cloning????//
Anders Nor?s [MCAD] - 14 Dec 2004 11:20 GMT
> Hi,
>      I've  a query in cloning. How cloning is different from creating a
> new
> instance of an object.? I suppose cloning also creates a new object and
> copies the exisitng object's data. Where and when should use cloning????//
You're right cloning an object creates a new instance of the class with the
same data as the existing instance.
There are two ways of cloning an object. You can create a shallow copy of an
object by calling the MemberwiseClone method inherited from System.Object. 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.
If the object implements the System.IClonable interface you can call the
Clone method to clone the object. Classes that implement IClonable control
how the instance is cloned. IClonable is often implemented to support
deep-copying of an object. In contrast to a shallow copy, a deep copy of an
object duplicates everything directly or indirectly referenced by the fields
in the object.

You should use Object.MemberwiseClone when you want a copy of an object with
the same references as the original and IClonable.Clone when you want a copy
of an entire object graph.

Anders Nor?s
http://dotnetjunkies.com/weblog/anoras/

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.