使用应用程序设置Properties.Settings [英] using Properties.Settings for application settings

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

问题描述

我使用由Visual Studio提供的内置设置存储简单的应用程序设置。

I use the built-in settings provided by Visual Studio to store simple application settings. Until now, I've accessed this in my application by using the convention:

Properties.Settings.Default.MySetting

,然后用如下调用保存方法:

And then call methods like Save by using:

Properties.Settings.Default.Save()

然而,最近有人告诉我,这是比较正确的通过创建一个成员变量这样的访问属性:

However, someone recently told me that it is more correct to access the properties by creating a member variable like this:

private Properties.Settings settings = new Properties.Settings()

和则使用成员设置来访问属性以及类似的方法:

And then using the member settings to access properties and methods like:

settings.MySetting
settings.Save()

我依稀记得,他们通过描述差异有道理这设置存储在用户的区域的方式。

I vaguely recall that they justified this by describing differences in the way the settings are stored in the user's area.

任何人都可以证实或差异透露更多细节? 。非常感谢

Can anyone confirm or give further details on the differences? Many thanks.

推荐答案

Settings.Default 如下初始化:

private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));



因此,它几乎一样手动创建一个设置实例,除了通过 Settings.Default 的一个是同步的实例。我看不到任何好的理由来创建设置的一个实例手动...

So it's almost the same as manually creating an instance of Settings, except that the one provided by Settings.Default is a synchronized instance. I can't see any good reason to create an instance of Settings manually...

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

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