6

The more options I have defined, the more a have to type when I have to modify them. So I'm looking for a shorter version of Properties.Settings.Default.varX

I tried:

Properties.Settings settings = Properties.Settings.Default;
settings.var1 = "x";
settings.var2 = "y";
settings.var3 = "Z";
Properties.Settings.Default = settings;

but Properties.Settings.Default is read-only and the Save function has no overload.

So is there any other way than typing Properties.Settings.Default again and again?

christophrus
  • 1,170
  • 2
  • 14
  • 27

3 Answers3

9

Just try it like this:

Properties.Settings settings = Properties.Settings.Default;
settings.var1 = "x";
settings.var2 = "y";
settings.var3 = "Z";
settings.Save();
LarsTech
  • 80,625
  • 14
  • 153
  • 225
  • 1
    Because `Properties.Settings` is a class, `settings` actually contains the same reference to `Properties.Settings.Default`. Changing properties to `settings` is equivalent to changing `Properties.Settings.Default`. – Alvin Wong Feb 02 '13 at 13:47
  • 1
    @AlvinWong Isn't that what he wants? – LarsTech Feb 02 '13 at 13:47
3

To shorten a little bit what you have to type you might try adding this to the initial using statements

using MyProps = <your_namespace>.Properties.Settings;

and then in code you could use

MyProps.Default.Var1 = "";

<your_namespace> should be replaced by the full namespace where the settings are defined.

Steve
  • 213,761
  • 22
  • 232
  • 286
0

Something I use that I find quite handy is the following:

var props = Properties.Settings.Default;

This way, if I type "props", it counts as if I have typed "Properties.Settings.Default". So I can type now

props.Name

instead of

Properties.Settings.Default.Name

Emre
  • 29
  • 10