【发布时间】:2017-06-22 21:36:46
【问题描述】:
我有一个结构(人)数组,我将其序列化并格式化如下
<Serializable()> Structure Person
Public strID As String
Public strName As String
Public strReport As String
Public strAttend As String
Public Shared Widening Operator CType(v As Person) As IO.MemoryStream
Try
Throw New NotImplementedException()
Catch ex As Exception
MsgBox("Failed to deserialise." + Chr(13) + "Reason: " & ex.Message)
End Try
End Operator
End Structure
Public Student(35) As Person
Dim bf As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
Dim ms as New System.IO.MemorySteam()
bf.Serialize(ms,Student(count))
My.Computer.FileSystem.WriteAllBytes(strFile1,ms.GetBuffer(),True)
根据需要创建和填充文件。当我用写字板检查时,所有记录都存在。 当我反序列化它时,如下所示,我只看到第一条记录重复。我在想指针没有移动,或者我要在每次迭代中返回记录 1。我错过了什么?
Public Student(35) As Person
Dim bf As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
Dim ms as New System.IO.MemorySteam()
Dim bytes As Byte() = My.Computer.FileSystem.ReadAllBytes(strFile1)
My.Computer.FileSystem.ReadAllBytes(strFile1)
Student(35) = DirectCast(bf.Deserialize(New MemoryStream(bytes)),Person)
ms.Seek(0,SeekOrigin.Begin)
For i = 0 to 19
Student(i) = DirectCast(bf.Deserialize(New MemoryStream(bytes)),Person)
Next
提前感谢您提供的任何帮助或建议。
【问题讨论】:
-
我是否给了你适当的信任(投票?)以获得一个很好的答案?我采纳了你的所有建议,改变了我的方法,一切都如你所说。非常感谢
-
是的。接受答案(复选标记)是您所能做的,直到您获得更多代表。然后,您可以为任何您认为有帮助的帖子点赞。
标签: .net vb.net serialization binaryformatter