 <p>I just use generics for things like this.</p> <pre><code>public static T GetConfigurationValue&lt;T&gt;(string keyName) { if (System.Configuration.ConfigurationManager.AppSettings[keyName] != null) { T result; try { result = (T)Convert.ChangeType(System.Configuration.ConfigurationManager.AppSettings[keyName], typeof(T)); } catch { return default(T); } return result; } throw new ArgumentException("A key with the name " + keyName + " does not exist in the current configuration.", keyName); } </code></pre> <p><strong>Usage:</strong> <code>GetConfigurationValue&lt;int&gt;("DefaultCookieExpiryMins");</code></p>