C#读写config配置文件

class Config
    {
        static Configuration _config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

        private Config()
        {
            
        }

        static public void AddAppSetting(string key, string value)
        {
            _config.AppSettings.Settings.Add(key, value);
            _config.Save();
        }

        static public void SetAppSetting(string key, string value)
        {
            _config.AppSettings.Settings.Remove(key);
            _config.AppSettings.Settings.Add(key, value);

            _config.Save();
        }

        static public string GetAppSetting(string key)
        {
            return _config.AppSettings.Settings[key].Value;
        }

        static public void DelAppSetting(string key)
        {
            _config.AppSettings.Settings.Remove(key);
            _config.Save();
        }

    }

 

posted @ 2018-09-19 12:35  xslwm  阅读(671)  评论(0编辑  收藏  举报