ConfigHelper类

ConfigHelper类用来读取web.config配置的数据

引入 using System.Configuration; 命名空间

public sealed class ConfigHelper

{

   public static string GetConfigString(string key)
  {
            return ConfigurationManager.AppSettings[key];
  }

  //可以以扩展得到布尔值

  public static bool GetConfigBool(string key)
  {
   bool result = false;
   string cfgVal = GetConfigString(key);
   if(!String.IsNullOEmpty(cfgVal))
   {
    try
    {
     result = bool.Parse(cfgVal);
    }
    catch(FormatException)
    {
     // Ignore format exceptions.
    }
   }

   return result;
  }

}

原文地址:https://www.cnblogs.com/chenqingwei/p/1743711.html