c# 配置文件App.config操作类库
生活随笔
收集整理的這篇文章主要介紹了
c# 配置文件App.config操作类库
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?
public class ConfigOperator{#region 從配置文件獲取Value/// <summary>/// 從配置文件獲取Value/// </summary>/// <param name="key">配置文件中key字符串</param>/// <returns></returns>public static string GetValueFromConfig(string key){try{Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);//獲取AppSettings的節點 AppSettingsSection appsection = (AppSettingsSection)config.GetSection("appSettings");return appsection.Settings[key].Value;}catch{return "";}}#endregion#region 設置配置文件/// <summary>/// 設置配置文件/// </summary>/// <param name="key">配置文件中key字符串</param>/// <param name="value">配置文件中value字符串</param>/// <returns></returns>public static bool SetValueFromConfig(string key, string value){try{//打開配置文件 Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);//獲取AppSettings的節點 AppSettingsSection appsection = (AppSettingsSection)config.GetSection("appSettings");appsection.Settings[key].Value = value;config.Save();return true;}catch{return false;}}#endregion?
轉載于:https://www.cnblogs.com/xuxiaoshuan/p/5884406.html
總結
以上是生活随笔為你收集整理的c# 配置文件App.config操作类库的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 个人对响应式布局的理解
- 下一篇: c语言作业