アプリケーション設定が利用可能かどうかを確認するにはどうすればよいですか?
例えばapp.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key ="someKey" value="someValue"/>
</appSettings>
</configuration>
そしてコードファイルでは
if (ConfigurationManager.AppSettings.ContainsKey("someKey"))
{
// Do Something
}else{
// Do Something Else
}
ベストアンサー1
if (ConfigurationManager.AppSettings[name] != null)
{
// Now do your magic..
}
または
string s = ConfigurationManager.AppSettings["myKey"];
if (!String.IsNullOrEmpty(s))
{
// Key exists
}
else
{
// Key doesn't exist
}