• 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.../////
    //////////////////////////////

  • 相关阅读:
    HDU 3572 Task Schedule(拆点+最大流dinic)
    POJ 1236 Network of Schools(Tarjan缩点)
    HDU 3605 Escape(状压+最大流)
    HDU 1166 敌兵布阵(分块)
    Leetcode 223 Rectangle Area
    Leetcode 219 Contains Duplicate II STL
    Leetcode 36 Valid Sudoku
    Leetcode 88 Merge Sorted Array STL
    Leetcode 160 Intersection of Two Linked Lists 单向链表
    Leetcode 111 Minimum Depth of Binary Tree 二叉树
  • 原文地址:https://www.cnblogs.com/sixiweb/p/1769283.html
Copyright © 2020-2023  润新知