In a nutshell: 1. Shallow copy: The value of all the fields of a type is assigned once. • The value of the value type and the reference type are copied one copy, the value of the reference type is the address pointed to by the original object reference, so the modification will change the reference point of the original object to the value. (String is a special class • Used as a value type is a non-reference type)
2. Deep copy: That is, the reference type refers to the class can also be copied a copy, the modification of the point will not change the value of the original reference point.
Here's how the deep copy is implemented:
The first is the serialization method: You can inherit the ICloneable implementation of its interface clone
[serializable]//cannot serialize if Carddata is not added to the serialized identity
public class Carddata:icarddata, icloneable
{
<summary>
Deep copy
</summary>
<returns></returns>
public Object Clone ()
{
using (Stream Objectstream = new MemoryStream ())
{
IFormatter formatter = new BinaryFormatter ();
Formatter. Serialize (Objectstream, this);
Objectstream.seek (0, Seekorigin.begin);
Return formatter. Deserialize (Objectstream) as Carddata;
}
}
There's another way to write a new constructor.
Public Carddata (Icarddata card)
{
Assign all fields in turn if the field is a lot, it's very painful.
}
About deep copies of C #