WinForms-哪种持久化数据最简单的方法是? [英] WinForms - which is easiest approach for persisting some data?

查看:81
本文介绍了WinForms-哪种持久化数据最简单的方法是?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只需构建我的第一个WinForms应用程序.

问题-在应用程序使用之间保存某些数据的最简单/最佳方法是什么(例如,在这种情况下,带有状态和日期/时间的URL列表)?我看不到需要数据库.

例如 *仅存储到文本文件最容易吗? *或将其存储到XML文件中就像在DotNet中一样容易 * Windows Registry怎么样-通常可以避免这种情况吗?它在包括Windows 7在内的所有版本中使用兼容吗 *数据库-可能在这里过大 *也许是一个广泛使用的图书馆?

谢谢

解决方案

在.NET中,存储到XML非常容易,特别是如果您实际上只是存储URL和时间戳.您可以创建一个自定义类来保存数据...在运行时,在您的应用中操纵该类的实例.

当需要保存时,将对象序列化为XML ...当应用程序稍后需要恢复数据时,只需反序列化即可. MSDN具有简单的演练.

值得注意的是,像Quintin一样,使用SQL Server Compact或其他轻量级数据库也是一个好主意. XML快速简便-但是,如果您需要人们共享数据,或者需要比简单序列化更灵活的东西,那么最好使用数据库.

Just building my first WinForms application.

Question - What's the easiest/best approach for saving some data between use of the application (e.g. list of URL with status & date/time in this case)? I don't see any need for a database.

For example * Is just storing to text file easiest? * Or is storing to XML file just as easy in DotNet * How about Windows Registry - is this something generally to avoid? Is it's use compatible across all versions including Windows 7 * Database - probably overkill here * A widely used library perhaps?

Thanks

解决方案

Storing to XML is very easy in .NET, particularly if you're really just storing a URL and a timestamp. You could create a custom class to hold the data... at runtime, manipulate instances of that class in your app.

When it's time to save, serialize the object(s) to XML... when the app needs to restore the data later, just deserialize. MSDN has a simple walkthrough.

It's worth noting, as Quintin did, that using SQL Server Compact or some other lightweight database might also be a good idea. XML's quick and easy - but if you need people to share data or you need anything more flexible than simple serialization, you're better off with a database.

这篇关于WinForms-哪种持久化数据最简单的方法是?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆