通过序列化实现深拷贝

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

 

class App
{

    public static void Main(string[] args)
    {

        abc abc1 = new abc();
        abc1.a = "a";
        abc1.b = "b";
        abc1.c = "c";
        MemoryStream memoryStream = new MemoryStream();
        BinaryFormatter formatter = new BinaryFormatter();
        formatter.Serialize(memoryStream, abc1);
        memoryStream.Position = 0;
        abc abc2 = (abc)formatter.Deserialize(memoryStream);
        Console.ReadLine();
    }

}

[Serializable]
public class abc
{
    public string a;
    public string b;
    public string c;
}

posted on 2011-09-19 22:09  上校  阅读(219)  评论(0编辑  收藏  举报