Why are application settings read-only in app.config?

后端 未结 6 1035
南方客
南方客 2020-12-09 02:00

I have some settings in my app.config which I intend to be \'global\' - ie. any user can change them, and all users get the same setting.

But unless I change them to

6条回答
  •  盖世英雄少女心
    2020-12-09 02:27

    The real complete answer:

    The app.config settings are read-only because there are 2 types of settings:

    1. Application Settings
    2. User Settings

    The first won't change unless the application publisher publishes a new version of it. The second is not stored in the app.config, but in a user.config file. In the abscence of this user.config file the app.config provides the default value.

    If MySetting is a User Setting:

    Settings.Default.MySetting = MyNewValue;
    Settings.Default.Save();
    

    It will create a user.config file at [User Local Settings Application Data]\[company name]\[application].exe[hash string]\[version] with the new settings, and those settings will prevail over the settings in the app.config file.

提交回复
热议问题