关于ConfigurationManager
来源:互联网 发布:运动手表推荐 知乎 编辑:程序博客网 时间:2024/06/05 01:15
前面的文章谈到了AppSettingsReader的应用,但有的童鞋在按照那篇文章做测试程序的时候发现写
ConfigurationSettings.AppSettings时会出现波浪线标示,会得到这样一个警告:
“System.Configuration.ConfigurationSettings.AppSettings”已过时:“This method is obsolete,
it has been replaced by System.Configuration!System.Configuration.ConfigurationManager.AppSettings”
但在根据提示修改为.ConfigurationManager时却死活找不到这个对象。
这里要说明一下,除了要通过using 来引用System.Configuration外,我们还必须在通过添加引用(.net选项页中)添加System.Configuration;
也就是说要添加对System.Configuration.dll 文件的引用才可以正常使用。
所以,我们见到This method is obsolete这样的提示就要注意对dll文件的引用。
This method is obsolete, it has been replaced by System.Configuration!System.Configuration.ConfigurationManager.AppSettings
添加完成后我们可以引用了
public NameValueCollection settings;
settings = ConfigurationManager.AppSettings ;//被替换的老版本ConfigurationSettings.AppSettings;//
这样我们就可以取到我们需要的键值了。如我们要删除或者是添加可以很简单的实现
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
//增
config.AppSettings.Settings.Add(key, value);
//删
config.AppSettings.Settings.Remove(key);
//改
config.AppSettings.Set("key", "value");
//存
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
最后这句是强制刷新。
- 关于ConfigurationManager
- 关于ConfigurationManager.GetSection()方法
- ConfigurationManager
- ConfigurationManager
- 关于System.Configuration.ConfigurationManager.AppSettings问题
- ConfigurationManager问题解决
- ConfigurationManager類別
- ConfigurationManager类
- ConfigurationManager 修改
- ConfigurationManager.OpenExeConfiguration
- ConfigurationManager Usage
- c# ConfigurationManager
- ConfigurationManager API
- ConfigurationManager不存在
- 关于错误“System.Configuration”中不存在类型或命名空间名称“ConfigurationManager”
- 关于错误“System.Configuration”中不存在类型或命名空间名称“ConfigurationManager”
- 古怪的ConfigurationManager类
- 古怪的ConfigurationManager类
- svn版本控制管理
- SqlServer操作远程数据库
- 报表the document has no pages的问题解决
- Java编程思想,第二章:一切都是对象
- google有问题?
- 关于ConfigurationManager
- 使用批处理将特定字符串之间的内容删掉,配合TopCoder中ExampleBuilder插件使用
- How do I cover the “no results” text in UISearchDisplayController's searchResultTableView?
- 哈工大某建设网站被挂马
- 视频服务器软件MJPG-streamer在嵌入式多媒体数据处理中的应用
- The driver of Synaptic touch controller
- android查看每个app的内存占用情况
- [leetcode]Binary Tree Inorder Traversal
- sql convert函数使用小结