以前没留意,今天搞了一把,呵呵,深拷贝。
using System;
namespace aa
{
public class Test
{
public class Person : ICloneable
{
public int X;
public int Y;
public Person()
{
}
public Person(int x, int y)
{
X = x;
Y = y;
}
public object Clone()
{
Person b = new Person();
b.X = this.X;
b.Y = this.Y;
return b;
}
}
static void Main(string[] argv)
{
Person a = new Person(1, 2);
Console.Out.Write(a.X+" " + a.Y+"/n");
Person b = (Person)a.Clone();
Console.Out.Write(b.X + " " + b.Y + "/n");
a.X = 10;
Console.Out.Write(a.X + " " + a.Y + "/n");
Console.Out.Write(b.X + " " + b.Y + "/n");
Console.ReadLine();
}
}
}