在 XML 设置文件中创建字符串列表
将字符串列表保存到设置文件的最佳方法是什么?我已经看到了一些将 xml 设置文件类型编辑为 string[] 的解决方案,但我可以让它在编辑器中工作。
我也不知道在运行时会添加多少字符串,而且会很多,所以我不想在这里定义一堆命名字符串。但我仍然想保存它们并在下次打开应用程序时访问。
我看到设置类型中有一个 System.Collections.Specialized.StringCollection
,这是我想要的吗?如果有一种方法可以将数组保存到 XML 中也可以。
what is the best way to save a list of strings to the settings file? i've seen some solutions of editing the xml setting file type to string[], but i can get that to work in the editor.
i also don't know how many strings are going to get added at runtime and it's going to be a lot so i don't want to define a bunch of named strings here. but i still want to save them and have access the next time the application is opened.
i see there is a System.Collections.Specialized.StringCollection
in the settings types, is this what i want? if there's a way to save an array to the XML that would work too.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个简单的 XML 编写器脚本。 (未经测试)
JavaScriptSerializer.Serialize() 也会做你想做的事情,但用途有限。如果您想要的只是简单,请使用 JavaScriptSerializer.Serialize()。
Here is a simple XML writer script. (untested)
JavaScriptSerializer.Serialize() will do what you want as well, but with limited use. If all you want is simple, use JavaScriptSerializer.Serialize().
也许这个问题How to store int[] array in application Settings 会有帮助。不过,如果您正在寻找一种快速简便的方法来完成此操作,您可以尝试将集合序列化为 json。
Perhaps this question How to store int[] array in application Settings will be of help. Tho if you're looking for a quick and easy way to do it, you could try just serializing the collection to json.