static void Main(string[] args) { Cloner mySource = new Cloner(5); Cloner myTarget = (Cloner)mySource.GetCopy(); Console.WriteLine("myTarget.MyContent.Val={0}", myTarget.MyContent.Val); //5 mySource.MyContent.Val = 2; Console.WriteLine("myTarget.MyContent.Var={0}", myTarget.MyContent.Val); Cloner2 mySource2 = new Cloner2(5); Cloner2 myTarget2 = (Cloner2)mySource2.Clone(); Console.WriteLine("myTarget2.MyContent.Val={0}", myTarget2.MyContent.Val); //5 mySource.MyContent.Val = 2; Console.WriteLine("myTarget2.MyContent.Var={0}", myTarget2.MyContent.Val); Console.ReadKey(); }
public object Clone() { Cloner2 clonedCloner = new Cloner2(MyContent.Val); return(clonedCloner); }