public T DeepCopy<T>(T arg)
{
BinaryFormatter formatter = new BinaryFormatter();
MemoryStream stream = new MemoryStream();
formatter.Serialize(stream, arg);
stream.Position = 0;
T result = (T)formatter.Deserialize(stream);
stream.Close();
return result;
}
http://blog.csdn.net/fangxinggood/article/details/369410 ------其他解决方案-------------------- 写程序首先考虑的是程序的正确性而不是怎么方便,看如下代码:
class A
{
public B Obj { get; set; }
}
class B
{
public string Text { get; set; }
}
A a1, a2;
a1 = new A() { Obj = new B() { Text = "a1" }};
如果A不是你设计的,请问你打算怎么复制a2?不要问我,我也不知道。 ------其他解决方案--------------------