C# Binary Serializing a Hybrid Dictionary

Shalvin 0 Tallied Votes 258 Views Share

Serialization is the process of saving the state of an object into persistant medium.
BinaryFormatter class is used for serializing and deserializing an object.

HybridDictionary is optimized for key-based item retrieval from both small and large collections.

using System.Collections;
using System.Collections.Specialized; 
using System.IO; 
using System.Runtime.Serialization.Formatters.Binary;

HybridDictionary hd; 
FileStream fs; 
BinaryFormatter bf; 

private void Form1_Load(object sender, EventArgs e)
{
hd = new HybridDictionary(); 
hd.Add("Sh", "Shalvin"); 
hd.Add("Sa", "Saji"); 

foreach (DictionaryEntry de in hd) 
listBox1.Items.Add(de.Key + " " + de.Value); 

fs = new FileStream(@"c:\Sh.data", FileMode.Create); 
bf = new BinaryFormatter(); 
bf.Serialize(fs, hd); 
fs.Close();
}
belynmoon 0 Newbie Poster

I like it very much!
Thank you !

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.