Skip to content

Instantly share code, notes, and snippets.

@csharpforevermore
Created November 25, 2013 22:27
Show Gist options
  • Save csharpforevermore/7650031 to your computer and use it in GitHub Desktop.
Save csharpforevermore/7650031 to your computer and use it in GitHub Desktop.
parse a web.config appsetting true / false to boolean.
bool isTest = Boolean.Parse(ConfigurationManager.AppSettings["appSettingValue"]);
@Ekus
Copy link

Ekus commented Nov 9, 2018

Hi, just googled this out but it will throw: ArgumentNullException: Value cannot be null.
when the setting is missing from config file. This one may be safer:

bool isTest = Boolean.Parse(ConfigurationManager.AppSettings["appSettingValue"] ?? "false");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment