使用Properties.Settings.Default保存设置 [英] Saving settings with Properties.Settings.Default

查看:533
本文介绍了使用Properties.Settings.Default保存设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我只是想知道是否有一种方法可以只保存一些特定设置以供会话之间使用.

Properties.Settings.Default.Save()保存所有内容,但是我只需要保存一些设置,其他设置在下一个会话开始时为空.


我这样做是为了在整个表单中将它们用作全局变量,我知道这样做有更好的方法,但是我的问题仍然存在,实际上是否有一种方法可以保存一些设置?

Hi,

I was just wondering if there is a way to save just some specific settings for use between sessions.

Properties.Settings.Default.Save() saves everything but i need only a few settings saved and others empty at the start of next session.


i did it in order to use them as global variables throughout forms, i am aware there are better ways for this but still my question stands, is there actually a way to save just some settings?

推荐答案

您错过了重点.有办法吗?也许(但可能不是),因为它们并不是要以这种方式使用.

当然,您可以将值存储在临时变量中,将设置中的值设置为空,保存,然后将临时值返回到设置中.那将得到您想要的效果.但这将变得更加难以维护,而这并不是做事的正确"方法.

您真正应该做的是将不需要保存的内容存储在静态类或单例中.然后,您所有的表单都可以访问相同的数据,并且您的设置实际上是设置.这确实是您应该寻求的解决方案,它可能并非您所要的,但是您将获得相同的结果,并且不必尝试在功能上寻找一些漏洞即可实现此目的. .使用语言和框架,不要试图与之抗争!
You''re missing the point. Is there a way? Maybe, but probably not, because they aren''t meant to be used that way.

Sure, you could store the value in a temporary variable, set the value in the settings to empty, save, then return the temporary values to the settings. That would get the effect you want. But it''s going to be harder to maintain, and it''s just not the "right" way to do things.

What you should really do is store the ones that do not need to be saved in a static class or a singleton. Then all your forms get access to the same data, and your settings are actually settings. This is really the solution you should go for, it may not be exactly what you''re asking for, but you will get the same result, and you don''t have to try and find some loop hole in functionality to achieve it. Work with the language and framework, don''t try to fight against it!


这篇关于使用Properties.Settings.Default保存设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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