Free Jobs
Reference




Dot Net Forums: ASPNET (77) C#.NET (39) VB.NET (8) AJAX (21) Silver Light (1) WCF (10) WPF (1) WWF (1) .NET 3.5 (3) SQL SERVER (38) Other (3)

Topic: What is difference between Copy and Cloning in C# or VB.NET

To get the Posted Questions details daily in your mail Click Here

Share this Post on Facebook/Twitter/Orkut Bookmark and Share





User: avinash222 Post Date: 20 Dec 2010 07:45

Introduction:
During programming in C# VB.NET some times we need to do copy and sometimes
we need to do cloning.There is a basic difference between them.



Main Content:
Copy of (say an array or object ) means copying the data of array or
object.Note that the copy may be Deep copy or Shallow copy which is explained at the end of this post.

Cloning of (say an array or object ) Generally means copying the structure
of array or object NOT the data it contains.Thus Shallow copy.
The method named this.MemberwiseClone( ) performs cloning by shallow copy.


Note that a Deep Cloning is also possible in .NET framework which does
Deep Copy.

Shallow Copy

Shallow Copy should be described separetely for value type and reference
type.
Value type: a copy of the field is performed
Reference type :The reference is copied NOT the object so original object
and its Shallow Copy refer to the same object.


Deep Copy

Deep Copy should be described separetely for value type and reference type.
Value type: a copy of the field is performed
Reference type :The object itself is copied, NOT only the reference so
original object and its Deep Copy refer to two different object.




Conclusion:
Cloning is generally done to understand the structure of an object
so that we can create similar objects with different data and thus generally
Shallow copy.



About Writer:
Hi All This is avinash from Gurgaon


Writer's Link:

Writer's Email:







Comments:
Post Comment





Similar Articles Top ArticlesLatest Articles Other Articles by this Author







www.freejobsreference.com Copyright © 2009-2011 | All Rights Reserved
All content of this website is protected by copyright laws and should not be reproduced in any form or by any means without written permission
(Best viewed in IE 8.0+ or Firefox 3.0+ at resolution of 1024 * 768 or higher)