C#读写app.config中的数据

配置文件内容格式:(app.config)

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
    <add key="DemoKey" value="*" />
</appSettings>
</configuration>

读语句:
          String str = ConfigurationManager.AppSettings["DemoKey"];

写语句:

           Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
           cfa.AppSettings.Settings["DemoKey"].Value = "DemoValue";
           cfa.Save();

From: http://gb2013.blog.163.com/blog/static/21735301201021253713453/

原文地址:https://www.cnblogs.com/shined/p/2141360.html