C# 深复制
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication13 { public class Content { public int Val2; } public class Cloner:ICloneable { public int Val; public Content Mycontent = new Content(); public Cloner(int newVal) { Mycontent.Val2 = newVal; Val=newVal; } public object Clone() { Cloner clonedCloner = new Cloner(Mycontent.Val2); return clonedCloner; } } class Tester { static void Main(string[] args) { Cloner source = new Cloner(5); Cloner target = (Cloner)source.Clone(); Console.WriteLine("{0},{1}",target.Val,target.Mycontent.Val2); source.Mycontent.Val2 = 8; Console.WriteLine("{0},{1}", target.Val, target.Mycontent.Val2); Console.ReadKey(); } } }