6

Ok, so I am working on a c# windows forms application and it uses different types of structures that hold data and display to the user. I want to use a saveDialogBox to allow the user to save the information(i.e configuration, state). The only way I can think to do this is to make a routine that goes through the structures and write the corresponding elements to a text file. Upon loading this routine would be used to load the data back.

This is of course a dumb way to do it I'll admit. Anything I've done in school was only writing to text files. Is there other ways to make some formatted file to save and load from?

I've been looking at serialization to save objects to files. I am not too sure how all this works though. help.

4

2 回答 2

2

保存您的应用程序设置..我认为这些链接会对您有所帮助

http://msdn.microsoft.com/en-us/library/aa730869%28VS.80%29.aspx http://www.thescarms.com/dotnet/AppSettings.aspx

如何在 Visual C# 中使用设置

于 2013-06-18T03:21:53.697 回答
-1

我这样做的“老派”方式一直是在程序执行期间将设置保存到数据库中(前提是您花时间确保您不会通过更新/插入来敲击数据库)。

如果我的应用程序需要更高效并且我需要能够轻松地调用我使用 System.Xml.Serialization(从内存)序列化为 XML 的已保存设置。XML 序列化是人类可读的,这很有帮助(但在处理时间方面不是最有效的)。

如果我需要更高的效率,您可以全程序列化为二进制。

我建议在回到这里之前完整地阅读/理解http://msdn.microsoft.com/en-us/library/Vstudio/ms233843.aspx 。我会说,一旦您阅读了本文,您将能够更好地决定您希望以哪种方式申请您的申请。

根据我的经验,解决问题的 DUMB 方法并不多,但是只要有足够的时间和研究,几乎总有更好的方法来解决这些问题。

于 2013-06-17T21:57:46.113 回答