表单关闭并重新加载时保留 Arraylist 值

发布于 2024-08-23 03:41:34 字数 454 浏览 3 评论 0原文

我有一个 List 并且我想在表单关闭时保留所有列表值并在下次打开表单时重新加载列表?我可以在哪里保存我的List

这是一个手机应用程序。

更新 1:使用 XMLSerializer

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

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

myXmlSerial.Serialize(myWrite, ItemArr);

异常“生成 XML 文件时出错”发生在 myXmlSerial.Serialize(myWrite, ItemArr) 行

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情绪少女 2024-08-30 03:41:34

是整个流程封闭,还是只是形式封闭?如果只是形式,大概您有一些对象仍然是“活动的” - 基本上列表应该在那里。

如果整个应用程序被关闭然后重新启动,您需要将数据保存到持久存储(例如使用 XML 序列化),然后在启动时重新加载。

如果您能提供有关该场景的更多信息,那将非常有帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文