views:

35

answers:

1

I have a List<myObject> and I want to keep all the list values when the form closed and reload the list when the form is open the next time? Where can I save my List<>?

It's a mobile phone app.

UPDATE 1: Using XMLSerializer

XmlSerializer myXmlSerial = new XmlSerializer(typeof(List<CtrlListItem>));

StreamWriter myWrite = new StreamWriter("/Storage Card/mydefault.xml");

myXmlSerial.Serialize(myWrite, ItemArr);

Exception "Error when generating XML file" happen at line myXmlSerial.Serialize(myWrite, ItemArr)

+2  A: 

Is the whole process being closed, or just the form? If it's just the form, presumably you have some objects which are still "live" - the list should be there, basically.

If the whole app is being closed down and then restarted, you'll need to save your data to persistent storage (e.g. with XML serialization) and then reload it on startup.

If you could give more information about the scenario, that would really help.

Jon Skeet
Thanks for your quick reply. In my situation, it required the whole app closed and then restart. In details, the list contains online news data and I want that when network closed, it can reload the news loaded before.
Thyphuong
@Thyphuong: Right. In that case I would suggest some sort of simple serialization format - XML is probably the most straightforward, if you haven't got much data.
Jon Skeet