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;
}
}
本文介绍了一个用于读取web.config配置文件的ConfigHelper类,该类提供了获取字符串和布尔值配置的方法,并进行了异常处理。
566

被折叠的 条评论
为什么被折叠?



