学习笔记-Serialization

1。什么样的对象可以被序列化
标记[Serializable]public class MyClass {}
怎样不使属性不被序列化呢?
[NonSerialized] int _cashSize;
标记变量或者说成员
//二进制流序列化
ArrayList l = new ArrayList();
for (int x=0; x< 100; x++)
{ l.Add (x); }
FileStream s = File.Create("foo.bin");
BinaryFormatter b = new BinaryFormatter();
b.Serialize(s, l);
s.Close();
//反序列化
FileStream s = File.OpenRead("foo.bin");
BinaryFormatter b = new BinaryFormatter(); 
ArrayList p = (ArrayList) b.Deserialize(s);
s.Close();
PrintValues(p);

//实现IFormater接口
IFormater formater = new BinaryFormater();
IFormater foramter = new SoapFormater();


//加密解密序列化的数据System.Security.Cryptography

xml序列化只能序列public成员
且序列化需要传入typeof(要序列化的对象)

posted on 2005-07-12 13:14  秋雨飘飞  阅读(725)  评论(0编辑  收藏  举报