手机
当前位置:查字典教程网 >编程开发 >C#教程 >c# 配置文件App.config操作类库的方法
c# 配置文件App.config操作类库的方法
摘要:实例如下:publicclassConfigOperator{#region从配置文件获取Value//////从配置文件获取Value//...

实例如下:

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操作类库的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持查字典教程网。

【c# 配置文件App.config操作类库的方法】相关文章:

C#利用com操作excel释放进程的解决方法

C#访问应用程序配置文件的方法

C#中执行批处理文件(*.bat)的方法代码

C# SendInput 模拟鼠标操作的实现方法

C#删除文件目录或文件的解决方法

C#操作config文件的具体方法

c#简单读取文本的实例方法

C#操作注册表的方法

C#获取全部目录和文件的简单实例

深入C#判断操作系统类型的总结详解

精品推荐
分类导航