colinramsay.co.uk

Integer app.config Values

23 Oct 2006

This is the nicest looking way I've come up with of reading an integer from the app.config. It also sets a default if the configuratation key doesn't exist or isn't an integer.

int notificationInterval;

// Try and find a configured value for this, but if it doesn't exist set it to 30 seconds.
if(!int.TryParse(ConfigurationManager.AppSettings["notificationCheckInterval"], out notificationInterval))
{
notificationInterval = 30000;
}

Yum.

Feedback or questions on this post? Create an issue on GitHub.