日期:2014-05-17 浏览次数:20426 次
public void SeralizeNow()
{
List<ClassToSeralize> listse = new List<ClassToSeralize>();
ClassToSeralize cl1 = new ClassToSeralize();
cl1.id = "1";
cl1.name = "XXX";
ClassToSeralize cl2 = new ClassToSeralize();
cl2.id = "2";
cl2.name = "XXXN";
listse.Add(cl1);
listse.Add(cl2);
SerializeMethod(listse);
}
public void SerializeMethod(List<ClassToSeralize> listPers)
{
//序列化
System.Runtime.Serialization.IFormatter form = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
Stream st=new MemoryStream();
form.Serialize(st,listPers);
st.Flush();
st.Position=0;
byte[] bytes=new byte[st.Length];
st.Read(bytes,0,Convert.ToInt32(st.Length));
string s = Encoding.ASCII.GetString(bytes);
st.Close();
}
public void DeSerializeNow(string s)
{
System.Runtime.Serialization.IFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
byte[] bytes = null;
bytes =Encoding.ASCII.GetBytes(s);
System.IO.Stream stream = new System.IO.MemoryStream(bytes);
List<ClassToSeralize> obj = (List<ClassToSeraliz