23 Star 202 Fork 79

BBBUG / BBBUG Windows Client

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Config.cs 1.56 KB
一键复制 编辑 原始数据 按行查看 历史
Hamm 提交于 2020-10-19 09:17 . init: 初始化项目
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
namespace BBBUG.COM
{
public class Config
{
/// <summary>
/// 写入值
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
public static void SetValue(string key, string value)
{
//增加的内容写在appSettings段下 <add key="RegCode" value="0"/>
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings[key] == null)
{
config.AppSettings.Settings.Add(key, value);
}
else
{
config.AppSettings.Settings[key].Value = value;
}
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件
}
/// <summary>
/// 读取指定key的值
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public static string GetValue(string key)
{
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings[key] == null)
return "";
else
return config.AppSettings.Settings[key].Value;
}
}
}
C#
1
https://gitee.com/bbbug_com/BBbug_Winform_Applicaiton.git
git@gitee.com:bbbug_com/BBbug_Winform_Applicaiton.git
bbbug_com
BBbug_Winform_Applicaiton
BBBUG Windows Client
master

搜索帮助