Dim BinFormatter As New Binary.BinaryFormatter()
Dim P As New Person()
Dim Persons As New ArrayList
P = New Person()
P.Name = "Person 1"
P.Age = 35
P.Income = 32000
Persons.Add(P)
P.Name = "Person 2"
P.Age = 50
P.Income = 72000
BinFormatter.Serialize(FS, Persons)
以存储序列化数据的文件为参数,调用一个BinaryFormatter实例的Deserialize方法,就会返回一个对象,然后把它转化为合适的类型。下面的代码反序列化文件中的所有对象,然后处理所有的Person对象:
FS = New System.IO.FileStream _
("c:\test.txt", IO.FileMode.OpenOrCreate)
Dim obj As Object
Dim P As Person(), R As Rectangle()
Do
obj = BinFormatter.Deserialize(FS)
If obj.GetType Is GetType(Person) Then
P = CType(obj, Person)
'''' Process the P objext
End If
Loop While FS.Position < FS.Length - 1
FS.Close()
下面的例子调用Deserialize方法反序列化真个集合,然后把返回值转换为合适的类型(Person):
FS = New System.IO.FileStream("c:\test.txt", IO.FileMod
上一页 [1] [2] [3] [4] 下一页
Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved. 闵涛 E_mail:admin@mintao.net(欢迎提供学习资源)
鄂公网安备 42011102001154号
站长:MinTao ICP备案号:鄂ICP备11006601号-18