How might one serialize a sorted dictionary?

  • Thread starter Thread starter mp
  • Start date Start date
M

mp

given a sorted dictionary of sorted dictionaries
Private m_profilesDict As Dictionary(Of String, Object) = New Dictionary(Of
String, Object)

If m_profilesDict.ContainsKey(ProfileName) Then
ProfileDict = m_profilesDict.Item(ProfileName)
Else
ProfileDict = New SortedDictionary(Of Double, String)
m_profilesDict.Add(ProfileName, ProfileDict)
End If
If ProfileDict.ContainsKey(dlength) Then
....
Else
ProfileDict.Add(dlength, "to be determined")
End If

so at runtime i might have
M_ProfileDict.Item ("A")
ProfileDict.Item("25").Value = "1"
ProfileDict.Item("36").Value = "2"
ProfileDict.Item("45").Value = "3"
M_ProfileDict.Item ("C")
ProfileDict.Item("15").Value = "1"
ProfileDict.Item("26").Value = "2"
ProfileDict.Item("35").Value = "3"
M_ProfileDict.Item ("D")
ProfileDict.Item("27").Value = "1"
ProfileDict.Item("39").Value = "2"
ProfileDict.Item("41").Value = "3"

what would be an easy way to store to file and read back from file in
another session of the app?
I didn't notice a SortedDictionary.Serialize(Filename) property on the
object.
:-)
thanks
mark
 
mp said:
given a sorted dictionary of sorted dictionaries
Private m_profilesDict As Dictionary(Of String, Object) = New Dictionary(Of
String, Object)

what would be an easy way to store to file and read back from file in
another session of the app?
I didn't notice a SortedDictionary.Serialize(Filename) property on the
object.
:-)

You can unload the data out of the dictionary creating an object of each
item and load the object into a List<T>.

http://support.microsoft.com/kb/316730

Here is a C# example of how to serialize/deserialize a List<T> of
objects to/from a file. I am sure you can find a VB.Net example use
Google to find it.

http://dotnetperls.com/serialize-list-tutorial

Of course, the object has to be known by both programs.
 
Back
Top