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 is difference cookie and session?

711


What is form method?

678


What is smpte vc-1?

753


What is asp.net? How is it different from asp?

733


Why we use content place holder in asp.net?

734






What is the difference between web config and machine config files?

756


Explain how does asp page work?

751


How to Insert/Add in ASPXgridview

739


How do you declare delegates and are delegates and events one and the same and explain how do you declare delegates and invoke them ?

3712


Can you edit data in the Repeater control? Which template must you provide, in order to display data in a Repeater control? How can you provide an alternating color scheme in a Repeater control? What property must you set, and what method must you call in your code, in order to bind the data from some data source to the Repeater control?

761


Describe session handling in a webfarm, how does it work and what are the limits?

792


What is meant by web application?

706


How many validators do ASP.NET have?

767


What is the asp.net mvc folder conventions? : asp.net mvc

626


What does passport and windows authentication mean in ASP.NET?

846