Office中国论坛/Access中国论坛
标题:
C#深复制的测试
[打印本页]
作者:
tianping
时间:
2014-4-3 22:51
标题:
C#深复制的测试
本帖最后由 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();
}
}
}
复制代码
作者:
寂静岭
时间:
2014-4-3 23:02
天平哥在C#上颇有悟性
作者:
tmtony
时间:
2014-4-3 23:16
天平哥,这么晚还在研究啊
作者:
tianping
时间:
2014-4-5 23:42
寂静岭 发表于 2014-4-3 23:02
天平哥在C#上颇有悟性
谢谢老师点拨
作者:
tianping
时间:
2014-4-5 23:43
tmtony 发表于 2014-4-3 23:16
天平哥,这么晚还在研究啊
站长辛苦!
欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/)
Powered by Discuz! X3.3