Looking for a shurtcut of Properties.Settings.Defa

2019-02-17 05:05发布

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?

2条回答
祖国的老花朵
2楼-- · 2019-02-17 05:26

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.

查看更多
不美不萌又怎样
3楼-- · 2019-02-17 05:43

Just try it like this:

Properties.Settings settings = Properties.Settings.Default;
settings.var1 = "x";
settings.var2 = "y";
settings.var3 = "Z";
settings.Save();
查看更多
登录 后发表回答