|
本帖最后由 tianping 于 2014-4-3 22:57 编辑
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace testConsole
- {
- enum work
- {
- dancer,
- teacher
- }
- class Man
- {
- public string Name { get; set; }
- public work W{get;set;}
- public object Clone()
- {
- Man newMan = new Man();
- newMan.W = this.W;
- newMan.Name = this.Name;
- return newMan;
- }
- }
- class A:ICloneable
- {
- public string S { get; set; }
- public Man P=new Man();
- public A MakeCopy()
- {
- return (A)Clone();
- }
- public object Clone()
- {
- A newA = new A();
- newA.S = this.S;
- newA.P =(Man) this.P.Clone();
- return newA;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- A a1 = new A();
- A a2 =(A) a1.MakeCopy();
- a1.S = "a1";
- a2.S = "a2";
- a1.P.W = work.dancer;
- a2.P.W = work.teacher;
- Console.WriteLine("a1.s:{0},a2.s:{1}",a1.S,a2.S);
- Console.WriteLine("a1.work:{0},a2.work:{1}", a1.P.W, a2.P.W);
- Console.ReadKey();
- }
- }
- }
复制代码
|
|