System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); //打开config文件
config.AppSettings.Settings["username"].Value = “username”; //写入
config.Save(ConfigurationSaveMode.Modified); //保存
string username = config.AppSettings.Settings["username"].Value ; //读出