Skip to content

Instantly share code, notes, and snippets.

@greatcodeeer
Last active August 16, 2020 09:55
Show Gist options
  • Save greatcodeeer/2d5f699c87b4b2bbcaae to your computer and use it in GitHub Desktop.
Save greatcodeeer/2d5f699c87b4b2bbcaae to your computer and use it in GitHub Desktop.
C# 操作配置文件 app.config
//工程里添加对system.configuration.dll程序集的引用
Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
cfa.AppSettings.Settings.Add("key", "Name");//添加节点
cfa.AppSettings.Settings["key"].Value = "name";//设置节点(如果节点为空,会抛出异常)
cfa.Save(); //关键的一步!保存修改。
string ConString = System.Configuration.ConfigurationSettings.AppSettings["key"];//读取节点
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment