What is a deep copy in .Net ?

 Posted by Bharathi Cherukuri on 4/26/2012 | Category: .NET Framework Interview questions | Views: 1506 | Points: 40

Deep Copy is creating a new object and then copying the non static fields of the current object to the new object.


public object DeepCopy(object obj)

MemoryStream ms = new MemoryStream();
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(ms, obj);

object retval;
ms.Seek(0, SeekOrigin.Begin);
retval = bf.Deserialize(ms);
return retval;

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response