using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ICloneable_test2 { class DeepCopy : ICloneable { public int[] v = { 1,2,3}; //初始化一个整型数组 public DeepCopy() //构造函数 { } private DeepCopy(int[] v) //构造函数 { this.v = (int[])v.Clone(); } public Object Clone() //ICloneable接口中的方法 { return new DeepCopy(this.v); } public void Display() { for (int i = 0; i < v.Length; i++) { Console.Write(v[i] + ", "); } Console.WriteLine(); } } class Client { public static void Main() { DeepCopy dc1 = new DeepCopy(); DeepCopy dc2=(DeepCopy)dc1.Clone(); dc1.v[0] = 9; dc1.Display(); dc2.Display(); } } }