zoukankan      html  css  js  c++  java
  • winform中读写配置文件appSettings 一节中的配置。

    代码

            
    #region 读写配置文件
            
    /// <summary>
            
    /// 修改配置文件中某项的值
            
    /// </summary>
            
    /// <param name="key">appSettings的key</param>
            
    /// <param name="value">appSettings的Value</param>
            public static void SetConfig(string key, string value)
            {
                Configuration config 
    = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

                
    if (config.AppSettings.Settings[key] != null)
                    config.AppSettings.Settings[key].Value 
    = value;
                
    else
                    config.AppSettings.Settings.Add(key, value);

                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection(
    "appSettings");
            }

            
    /// <summary>
            
    /// 读取配置文件某项的值
            
    /// </summary>
            
    /// <param name="key">appSettings的key</param>
            
    /// <returns>appSettings的Value</returns>
            public static string GetConfig(string key)
            {
                
    string _value = string.Empty;
                Configuration config 
    = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                
    if (config.AppSettings.Settings[key] != null)
                {
                    _value 
    = config.AppSettings.Settings[key].Value;
                }
                
    return _value;
            }
            
    #endregion
    下面的图片显示不出来? 这里是图片开始:


    这里是图片结束。

    ////////////////////////////////
    ////////Sixi. Let it be.../////
    //////////////////////////////

  • 相关阅读:
    Java单例模式:为什么我强烈推荐你用枚举来实现单例模式
    为什么阿里Java规约要求谨慎修改serialVersionUID字段
    使用MyCat实现MySQL读写分离
    你知道HTTP协议的ETag是干什么的吗?
    在centos7中安装MySQL5.7
    MySQL实现主从复制功能
    Leetcode题目169.求众数(简单)
    Leetcode题目160.相交链表(简单)
    Leetcode题目155.最小栈(简单)
    Leetcode题目152.乘积最大子序列(动态规划-中等)
  • 原文地址:https://www.cnblogs.com/sixiweb/p/1769283.html
Copyright © 2011-2022 走看看