[Serializable()]
    class LeafClassDataPack
    {
        public string a;
        public int b;
        public byte[] c; 
    }
下面是测试代码:
private void button3_Click(object sender, EventArgs e)
        {
            LeafClassDataPack lcdp= DeserializeMyClass(SerializeMyClass());
            Text = lcdp.a;
        }
        private byte[] SerializeMyClass()
        {
            LeafClassDataPack leafClassDataPack=new LeafClassDataPack();
            leafClassDataPack.a = "test";
            byte[] leafMyClassByteTemp; 
            MemoryStream leafMemoryStreamTemp = new MemoryStream(); 
            BinaryFormatter leafBinaryFormatterTemp = new BinaryFormatter(); 
            leafBinaryFormatterTemp.Serialize(leafMemoryStreamTemp, leafClassDataPack); 
            leafMyClassByteTemp = leafMemoryStreamTemp.GetBuffer(); 
            return leafMyClassByteTemp;
        }
        private LeafClassDataPack DeserializeMyClass(byte[] leafMyClassByteTemp)
        {
            LeafClassDataPack leafClassDataPack;
            BinaryFormatter leafBinaryFormatterTemp = new BinaryFormatter();
            leafClassDataPack = (LeafClassDataPack)leafBinaryFormatterTemp.Deserialize(new MemoryStream(leafMyClassByteTemp));
            return leafClassDataPack;
        }