二进制序列化与应用程序设置 (user.config)
我正在使用 C# (.Net 2.0) 开发 Windows 应用程序。我需要存储近 50 到 60 个用户设置。 请问谁能告诉我以下哪个更好?
二进制序列化或应用程序设置(user.config)
谢谢。
I am using C# (.Net 2.0) to develop windows application. I need to store nearly 50 to 60 user settings.
Can anyone, please, tell which is better of the following?
Binary Serialization or Application Settings (user.config)
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
应用程序设置是内置的,可以运行,并且有 IDE 支持。
对于这一小组数据来说,性能并不是真正的问题;对于二进制文件,在这种情况下我会积极避免
BinaryFormatter
,因为应用程序设置通常会在版本之间演变,并且BinaryFormatter
在出现时非常脆弱到版本控制。还有其他方法可以将数据序列化为二进制,但在这种情况下我不确定我是否会打扰......App-settings is built in, works, and has IDE support.
Performance isn't really an issue for this small set of data; re binary, I would actively avoid
BinaryFormatter
in this case, since app-settings typically evolve between versions, andBinaryFormatter
is very brittle when it comes to versioning. There are other ways to serialize data as binary, but in this case I'm not sure I'd bother...这取决于您的需求。
二进制当然更快,如果你有大量数据,当
手写或可读,并且
如果性能不是一个大问题并且您希望它是人类可读的,则用户应用程序设置。
It depends on your needs.
Binary is faster of course, and you can use it if you have a large amount of data, when
hand or readable, and
User application settings if performance is not such a big concern and you want it to be human-readable.
您是否希望能够轻松编辑它们,而无需编写自己的界面?然后应用程序设置就是要走的路。
但是,如果您可能存储复杂类型,并且不需要在您允许的方式之外进行编辑,那么
BinarySerialization
会更好。您可能需要详细说明一下,但我认为应用程序设置可能是一个很好的方法。Do you want to be able to edit them easily, without writing your own interface? Then the application settings is the way to go.
But if you may be storing complex types, and there is no requirement to edit outside of the fashion you allow, then
BinarySerialization
would be preferable. You may need to elaborate a bit, but I think the Application Settings may be a fine approach.