|
shenyoujia
- 管理员
- 14848
- 1423
-
2009-11-07
|
shenyoujia
2010-02-01 09:43
|只看楼主
1#
t
T
- class DrawBase:System.Object , ICloneable
- {
- public string name = "jmj";
- public DrawBase()
- {
- }
-
- public object Clone()
- {
- return this as object; //引用同一个对象
- return this.MemberwiseClone(); //浅复制
- return new DrawBase() as object;//深复制
- }
- }
- class Program
- {
-
- static void Main(string[] args)
- {
- DrawBase rect = new DrawBase();
- Console.WriteLine(rect.name);
- DrawBase line = rect.Clone() as DrawBase;
- line.name = "a9fs3";
- Console.WriteLine(rect.name);
- DrawBase ploy = line.Clone() as DrawBase;
- ploy.name = "lj";
- Console.WriteLine(rect.name);
-
- Console.WriteLine(object.ReferenceEquals(line, ploy));
- Console.ReadLine();
- }
- }
复制代码
|