How to make a copy of a reference type
Possible Duplicate:
Cloning objects in C#
I have a class with properties and some of them are reference types (instances of other classes) themselves ( CookieContainer
).
I want to have a exact copy of this class so any change to previous version would not affect this new instance.
Is there a general solution for this kind of problems or I should do it manually ?
You need to deep copy the object to another object. There are many approaches to this but serializing one object and deserializing that data into another object is a very quick trick to achieve this. See it here: How do you do a deep copy of an object in .NET (C# specifically)?
确定您希望复制和实现ICloneable接口和克隆方法的深度:http://msdn.microsoft.com/en-us/library/system.icloneable.aspx
链接地址: http://www.djcxy.com/p/40760.html上一篇: C#中的深克隆类和子类
下一篇: 如何制作参考类型的副本