通过序列化和反序列化应该比较方便:classa b, a=new classa();System.IO.MemoryStream ms=new System.IO.MemoryStream();
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter=new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();formatter.Serialize(ms, a);
byte[] buffer=ms.GetBuffer();
ms.Close();ms=new System.IO.MemoryStream(buffer);
b=(classa)formatter.Deserialize(ms);
ms.Close();MessageBox.Show(a.Equals(b).ToString());

解决方案 »

  1.   

    Clone是从外部复制一个对象。我想从一个对象内部将通过类似复制的办法转自己复制成与传递给自己的另一个同类型对象一样。比如:
    public class Test
    {
          public string field1;
          private string field2;      public void Copy(Test obj)
          {
               // 不是field1 = obj.field1;
               复制(obj)
          }
    }public class Run
    {
    public static void Main()  
    {
         
                    Test a, b;
                    a.field1 = "OK";
                    b.Copy(a);
              }
    }看起来这样做似乎很蹩脚,没必要,但是我很想知道有没有方法可以如此实现。