//读配置文件 方法(1)
//ConfigurationManager.RefreshSection("appSettings"); //强制重新载入
string settingValue = ConfigurationManager.AppSettings.Get("setting1");
//读配置文件 方法(2)
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
string settingValue = config.AppSettings.Settings["setting1"].Value;
//写配置文件
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["setting1"].Value = "123";
config.Save(ConfigurationSaveMode.Modified);
//App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="setting1" value="123" />
</appSettings>
</configuration>
WinForm 读写配置文件
本文转载:CSDN博客