标签:
<?xml version="1.0" encoding="utf-8"?> <configuration> <connectionStrings> </connectionStrings> <appSettings> <add key="沉鱼" value="西施"/> <add key="落雁" value="昭君"/> <add key="闭月" value="貂蝉"/> <add key="羞花" value="杨贵妃"/> </appSettings> </configuration>
1.添加引用 => .NET 组件 => System.Configuration
2.读取配置文件
string name = ConfigurationManager.AppSettings["name"];
3.获取配置文件对象
ConfigurationUserLevel configurationUserLevel = ConfigurationUserLevel.None; Configuration configuration = ConfigurationManager.OpenExeConfiguration(configurationUserLevel);
4.新增
configuration.AppSettings.Settings.Add("四大美女", "沉鱼落雁,闭月羞花");
5.修改
configuration.AppSettings.Settings["闭月"].Value = "小貂蝉";
标签:
原文地址:http://www.cnblogs.com/me-code/p/4291438.html