开发者

Retain Arraylist values when form closed and reload

开发者 https://www.devze.com 2022-12-21 18:37 出处:网络
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 t开发者_StackOverflowhe next time? Where can I save my List<>?

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 t开发者_StackOverflowhe 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)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消