What is a deep copy in .Net ?

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

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

Example:

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);
ms.Close();
return retval;
}


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response