How would one do a deep copy in .NET?

Answer Posted / mario j vargas

You can perform a deep copy in C# by implementing the
ICloneable interface and manually assigning the values of
each member field in the current instance to the new
instance being returned. It is important to mention in the
implementation's documentation whether or not the copy is a
shallow or deep copy.

Bhagyesh suggested using a copy constructor. This is
something I had never seen in C#, only in C++, but the idea
sounded very compelling and I think this could be another
way to achieve a deep copy. You should check out the article
"How to: Write a Copy Constructor (C# Programming Guide)" in
the MSDN documentation.

Is This Answer Correct ?    4 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What should you do is you want to remove an existing component but would like to make some funtionalities?

1472


How can you handle exceptions in asp.net?

556


Will the asp.net validators run in server side or client side? How do you do client-side validation in .net? How to disable validator control by client side javascript?

516


Explain what is event bubbling?

566


What is request and response in asp.net?

502






What is simple data binding?

509


Explain the difference between web user control and web custom control?

532


How many types of cookies are available in asp?

568


What is the difference between exe and dll?

551


What is the purpose of App_Code folder in ASP.NET? Why we this?

598


What is a web api? Which protocol is used in a web api?

539


Explain how viewstate is being formed?

533


How do u deploy ur project?

2213


What is css and what is it used for?

550


What is a web farm?

586