开发者

How to determine appconfig contains a specific key [duplicate]

This question already has answers here: Closed 10 years ago.

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
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜