i have a class which has a string and a hash table.hash table contains set of key(string) values and bitmap file for each key attribute. how do i serialize this into binary file?
public void SerializeObject(List<Poem> poems)
{
using (Stream stream = File.Open("data.bin", FileMode.Create))
{
BinaryFormatter bin = new BinaryFormatter();
bin.Serialize(stream, poems);
}
}
public List<Poem> DeSerializeObject()
{
List<Poem> poems1;
using (Stream stream = File.Open("data.bin", FileMode.Open))
{
BinaryFormatter bin = new BinaryFormatter();
var lizards2 = (List<Poem>)bin.Deserialize(stream);
poems1 = (List<Poem>)lizards2;
}
return poems1;
}
//poem class
[Serializable()]
public class Poem
{
string poemName;
Hashtable poemContent; contains set of keys(strings) , values(bitmap)//
public Poem() {
poemContent = new Hashtable();
}
public string PoemName
{
get { return poemName; }
set { poemName = value; }
}
public Hashtable PoemContent
{
get { return poemContent; }
set { poemContent = value; }
}}
but this always generates errors.