How to determine appconfig contains a specific key [duplicate]
Possible Duplicate:
开发者_高级运维 C# assembly > app settings > how to check if one exists?
In the app.config, How can I know if it contains a specific key?
var specificValue = ConfigurationManager.AppSettings["specificKey"];
if (!string.IsNullOrEmpty(specificValue))
{
// Use the value
}
but if you only want to check the presence you could also:
if (ConfigurationManager.AppSettings.AllKeys.Contains("specificKey"))
{
// the config file contains the specific key
}
Try this:
if(ConfigurationManager.AppSettings["yourkey"] != null)
{
// that key exists..... do something with it
}
精彩评论