C# 配置文件操作类

瞩目增加引用:System.Configuration;

图片 1图片 2

 using System;  
using System.Collections.Generic;  
using System.Text;  
using System.Configuration;  

namespace DotNet.Utilities.配置文件操作类  
{  
    public class ConfigHelper_sufei  
    {  
        /// <summary>  
        /// 根据Key取Value值  
        /// </summary>  
        /// <param name="key"></param>  
        public static string GetValue(string key)  
        {  
            return ConfigurationManager.AppSettings[key].ToString().Trim();  
        }  

        /// <summary>  
        /// 根据Key修改Value  
        /// </summary>  
        /// <param name="key">要修改的Key</param>  
        /// <param name="value">要修改为的值</param>  
        public static void SetValue(string key, string value)  
        {  
            ConfigurationManager.AppSettings.Set(key, value);  
        }  

        /// <summary>  
        /// 添加新的Key ,Value键值对  
        /// </summary>  
        /// <param name="key">Key</param>  
        /// <param name="value">Value</param>  
        public static void Add(string key, string value)  
        {  
            ConfigurationManager.AppSettings.Add(key, value);  
        }  

        /// <summary>  
        /// 根据Key删除项  
        /// </summary>  
        /// <param name="key">Key</param>  
        public static void Remove(string key)  
        {  
            ConfigurationManager.AppSettings.Remove(key);  
        }  
    }  
}  

ConfigHelper

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图