How would one do a deep copy in .NET?

Answer Posted / rad

public static T DeepCopy<T>(T obj)
{
object result = null;

using (var ms = new MemoryStream())
{
var formatter = new BinaryFormatter();
formatter.Serialize(ms, obj);
ms.Position = 0;

result = (T)formatter.Deserialize(ms);
ms.Close();
}

return (T)result;
}

Is This Answer Correct ?    7 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a postback ispostback and autopostback in asp net?

470


How to find last error which occurred?

529


What is the use of placeholder control? Can we see it at runtime?

567


How Can assign alias name for ASP.NET Web API Action?

931


What is query string? What are its advantages and limitations?

507






How would you get asp.net running in apache web servers?

534


Explain the different types of directives in .net?

513


What is ASLM?

673


Define data caching?

537


What is hidden field in asp.net?

588


What are the different types of proxy patterns?

588


What is the difference between abstract class vs interface? Can give me the real time examples?

482


Describe the sequence of action takes place on the server when ASP.NET application starts first time?

614


What are the cookies types in asp.net?

553


How do you deploy your asp.net application?

528