T
Tony Johansson
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<Product> products = 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("Products.bin", FileMode.Create,
FileAccess.Write);
serializer.Serialize(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<Products> in the way shown below or can I use other construction.
FileStream loadFile = new FileStream("Products.bin", FileMode.Open,
FileAccess.Read);
List<Product> savedProducts =
serializer.Deserialize((List<Product>)loadFile);
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<Product> products = 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("Products.bin", FileMode.Create,
FileAccess.Write);
serializer.Serialize(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<Products> in the way shown below or can I use other construction.
FileStream loadFile = new FileStream("Products.bin", FileMode.Open,
FileAccess.Read);
List<Product> savedProducts =
serializer.Deserialize((List<Product>)loadFile);
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