static int GetValueAsIntAndValidate(string section, string key, int defaultValue, int minValue, int maxValue) { int retValue; using (Settings xmlreader = new MPSettings()) { retValue = xmlreader.GetValueAsInt(section, key, defaultValue); } // validate if (retValue < minValue || retValue > maxValue) retValue = defaultValue; return retValue; }