The following is the definition of app.config or web.config, which defines a parameter with the key Isinit and the value false
< ;add key ="IsInit" value="false"/>
The following are the method definitions for reading and writing config files:
Write:
internal void settingApp_write(string key, string val) { System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); config.AppSettings.Settings["IsInit"].Value = val; config.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection("appSettings"); }
Read :
internal string settingApp_read(string key) { var val = ConfigurationManager.AppSettings[key]; return val; }
Usage:
Write test:
settingApp_write("IsInit","true");
Take out test:
var setting = settingApp_read("Isinit");
The modifications at this level are Project-level config file modification is the operation of the config file in the Bin directory of your final program.
For more related articles on specific methods of operating config files in C#, please pay attention to the PHP Chinese website!