c# 配置文件App.config操作类库的方法
发布时间:2020-12-15 06:15:27 所属栏目:百科 来源:网络整理
导读:实例如下: public class ConfigOperator { #region 从配置文件获取Value /// summary /// 从配置文件获取Value /// /summary /// param name="key"配置文件中key字符串/param /// returns/returns public static string GetValueFromConfig(string key) { t
实例如下: public class ConfigOperator { #region 从配置文件获取Value /// <summary> /// 从配置文件获取Value /// </summary> /// <param name="key">配置文件中key字符串</param> /// <returns></returns> public static string GetValueFromConfig(string key) { try { Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); //获取AppSettings的节点 AppSettingsSection appsection = (AppSettingsSection)config.GetSection("appSettings"); return appsection.Settings[key].Value; } catch { return ""; } } #endregion #region 设置配置文件 /// <summary> /// 设置配置文件 /// </summary> /// <param name="key">配置文件中key字符串</param> /// <param name="value">配置文件中value字符串</param> /// <returns></returns> public static bool SetValueFromConfig(string key,string value) { try { //打开配置文件 Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); //获取AppSettings的节点 AppSettingsSection appsection = (AppSettingsSection)config.GetSection("appSettings"); appsection.Settings[key].Value = value; config.Save(); return true; } catch { return false; } } #endregion 以上这篇c# 配置文件App.config操作类库的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持编程小技巧。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- objective-c – 为什么在项目中使用’assert’? (以及为何
- ruby-on-rails – rails by by和按列排序
- c# – 创建Visual Studio样式选项/设置对话框
- sqlite – IndexedDB性能和IndexedDB v/s WebSQL性能比较
- XML2
- iphone – 来电唤醒iOS后台应用程序?
- c – 为openGL提供3D坐标的顺序是什么?
- reactjs – React中是否仍然需要使用自动绑定和属性初始值设
- swift – 红色的Pods框架(Xcode无法识别)
- scikit-learn – sklearn Pipeline和DataFrameMapper有什么