Last active
August 16, 2020 09:55
-
-
Save greatcodeeer/2d5f699c87b4b2bbcaae to your computer and use it in GitHub Desktop.
C# 操作配置文件 app.config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//工程里添加对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