1 public string SerializeObject(object obj) 2 { 3 //将object类型对象(注:必须是可序列化的对象)转换为二进制序列字符串 4 IFormatter formatter=new BinaryFormatter(); 5 string result=string.Empty; 6 using(MemoryStream stream=new MenmoryStream()) 7 { 8 formatter.Serialize(sream.obj); 9 byte[] byt=new byte[stream.Length]; 10 byt=stream.ToArray(); 11 //result=Encoding.UTF8.GetString(byt,0,byt.Length); 12 result=Convert.ToBase64String(byt); 13 stream.Flust(); 14 } 15 return result; 16 }