Hello!
Assume I have a class called Product which is defined with the attribute
[Serializable]
I create a collection by using the generic class List in this way
List<Productpro ducts = new List<Product>() ;
product.Add(new Product(1, "some name 1",120));
product.Add(new Product(1, "some name 2",130));
product.Add(new Product(1, "some name 3",140));
IFormatter serializer = new BinaryFormatter ();
FileStream saveFile = new FileStream("Pro ducts.bin", FileMode.Create ,
FileAccess.Writ e);
serializer.Seri alize(saveFile, products);
saveFile.Close( );
Now to my question.
When I want to deserialize do I then have to use the same kind of generic
construction
with List<Productsin the way shown below or can I use other construction.
FileStream loadFile = new FileStream("Pro ducts.bin", FileMode.Open,
FileAccess.Read );
List<Productsav edProducts =
serializer.Dese rialize((List<P roduct>)loadFil e);
loadFile.Close( );
My second question:
I'm reading in a book and they say the following.
"Some object don't serialize very well. They may require reference to local
data that only exist
while they are in memory, for example."
What does this mean.
//Tony
Assume I have a class called Product which is defined with the attribute
[Serializable]
I create a collection by using the generic class List in this way
List<Productpro ducts = new List<Product>() ;
product.Add(new Product(1, "some name 1",120));
product.Add(new Product(1, "some name 2",130));
product.Add(new Product(1, "some name 3",140));
IFormatter serializer = new BinaryFormatter ();
FileStream saveFile = new FileStream("Pro ducts.bin", FileMode.Create ,
FileAccess.Writ e);
serializer.Seri alize(saveFile, products);
saveFile.Close( );
Now to my question.
When I want to deserialize do I then have to use the same kind of generic
construction
with List<Productsin the way shown below or can I use other construction.
FileStream loadFile = new FileStream("Pro ducts.bin", FileMode.Open,
FileAccess.Read );
List<Productsav edProducts =
serializer.Dese rialize((List<P roduct>)loadFil e);
loadFile.Close( );
My second question:
I'm reading in a book and they say the following.
"Some object don't serialize very well. They may require reference to local
data that only exist
while they are in memory, for example."
What does this mean.
//Tony
Comment