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
is initialized as follows:
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
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...
This wasted a lot of my time.
[MyAppNameSpace].Properties.Settings.Default.Save();
Not sure when you can drop the namespace as above but in wpf in the app.xaml.cs code I needed to specify the namespace to get it to compile.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With