1 using System; 2 3 namespace Prototype 4 { 5 ///6 /// 作者:bzyzhang 7 /// 时间:2016/5/24 19:46:36 8 /// 博客地址:http://www.cnblogs.com/bzyzhang/ 9 /// WorkExperience说明:本代码版权归bzyzhang所有,使用时必须带上bzyzhang博客地址 10 /// 11 public class WorkExperience:ICloneable12 {13 private string workData;14 15 public string WorkData16 {17 get { return workData; }18 set { workData = value; }19 }20 21 private string company;22 23 public string Company24 {25 get { return company; }26 set { company = value; }27 }28 29 public object Clone()30 {31 return (object)this.MemberwiseClone();32 }33 }34 }
1 using System; 2 3 namespace Prototype 4 { 5 ///6 /// 作者:bzyzhang 7 /// 时间:2016/5/24 19:36:45 8 /// 博客地址:http://www.cnblogs.com/bzyzhang/ 9 /// Resume说明:本代码版权归bzyzhang所有,使用时必须带上bzyzhang博客地址 10 /// 11 public class Resume:ICloneable12 {13 private string name;14 private string sex;15 private string age;16 17 private WorkExperience workExperience;18 19 public Resume(string name)20 {21 this.name = name;22 workExperience = new WorkExperience();23 }24 25 private Resume(WorkExperience work)26 {27 this.workExperience = (WorkExperience)work.Clone();28 }29 30 public void SetPersonalInfo(string sex,string age)31 {32 this.sex = sex;33 this.age = age;34 }35 36 public void SetWorkExperience(string timeArea,string company)37 {38 workExperience.WorkData = timeArea;39 workExperience.Company = company;40 }41 42 public void Display()43 {44 Console.WriteLine("{0}{1}{2}",name,sex,age);45 Console.WriteLine("工作经历:{0}{1}", workExperience.WorkData, workExperience.Company);46 }47 48 public object Clone()49 {50 Resume obj = new Resume(this.workExperience);51 obj.name = this.name;52 obj.sex = this.sex;53 obj.age = this.age;54 55 return obj;56 }57 }58 }
1 using System; 2 namespace Prototype 3 { 4 class Program 5 { 6 static void Main(string[] args) 7 { 8 Resume a = new Resume("大鸟"); 9 a.SetPersonalInfo("男","29");10 a.SetWorkExperience("1998-2000","xx公司");11 12 Resume b = (Resume)a.Clone();13 b.SetWorkExperience("1998-2006","YY企业");14 15 Resume c = (Resume)a.Clone();16 c.SetPersonalInfo("男","24");17 c.SetWorkExperience("1998-2003","ZZ企业");18 19 a.Display();20 b.Display();21 c.Display();22 }23 }24 }