C# app.config 配置文件使用

来源:互联网 发布:ubuntu 添加路由 编辑:程序博客网 时间:2024/05/16 07:38
1、新建App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
    <add key="K" value="V" />
</appSettings>
</configuration>

2、添加引用
先在工程里添加system.configuration.dll程序集的引用
using System.Configuration;

3、读
string myvalue = ConfigurationManager.AppSettings["K"];

4、写
Configuration cfg = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
cfg.AppSettings.Settings["K"].Value = "自定义值";
cfg.Save();

ConfigurationManager.RefreshSection("appSettings");


转:http://greatverve.cnblogs.com/archive/2011/07/18/app-config.html

原创粉丝点击