The following is the definition of app.config or web.config, which defines a parameter, the key is Isinit, and the value is False
<?xml version= "1.0"?>
<configuration>
<appSettings>
<add key = "Isinit" value= "false"/>
</appSettings>
</configuration>
The following is the method definition for the read and write config file:
Write:
Copy Code code as follows:
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:
Copy Code code as follows:
Internal string Settingapp_read (string key)
{
var val = Configurationmanager.appsettings[key];
return Val;
}
How to use:
Write test:
Settingapp_write ("Isinit", "true");
To remove a test:
var setting = Settingapp_read ("Isinit");
This level of modification is the project-level config file modification, which is the operation of the config file in your final program Bin directory.