我有以下 System.Collections.Specialized.NameValueCollection 实例:
Dim UserSelection As New System.Collections.Specialized.NameValueCollection
UserSelection.Add("D_Color1", "Black")
UserSelection.Add("D_Color2", "Green")
UserSelection.Add("D_Color3", "Purple")
我需要将此实例保存到硬盘,然后作为实例从硬盘加载回来。我怎么做?
最佳答案
使用 BinaryFormatter
Using fs As New FileStream("DataFile.dat", FileMode.Create)
Dim formatter As New BinaryFormatter
formatter.Serialize(fs, UserSelection)
End Using
并反序列化
Using fs As New FileStream("DataFile.dat", FileMode.Open)
Dim formatter As New BinaryFormatter
UserSelection = DirectCast(formatter.Deserialize(fs), NameValueCollection)
End Using
关于.net - 如何将 System.Collections.Specialized.NameValueCollection 实例保存到硬盘并将其作为实例加载回来?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6473477/