TryParseInt() public static method

public static TryParseInt ( string str, int &n ) : bool
str string
n int
return bool
Example #1
0
        public static int GetInt(KeyValuePair <string, string> kvp)
        {
            int    nValue;
            string str;

            if (m_cfgCurrent.TryGetValue(kvp.Key, out str))
            {
                if (StrUtil.TryParseInt(str, out nValue))
                {
                    return(nValue);
                }
                else
                {
                    Debug.Assert(false);
                }
            }

            if (StrUtil.TryParseInt(kvp.Value, out nValue))
            {
                return(nValue);
            }
            else
            {
                Debug.Assert(false);
            }

            return(0);
        }
Example #2
0
        /// <summary>
        /// Get an integer value from the current configuration.
        /// </summary>
        /// <param name="strField">Name of the configuration item.</param>
        /// <param name="nDefaultIfNotFound">Default value that is returned if
        /// the specified item cannot be found.</param>
        /// <returns>An integer.</returns>
        /// <exception cref="System.ArgumentNullException">Thrown if <paramref name="strField" />
        /// is <c>null</c>.</exception>
        public static int GetInt(string strField, int nDefaultIfNotFound)
        {
            Debug.Assert(strField != null);
            if (strField == null)
            {
                throw new ArgumentNullException("strField");
            }

            string str;

            if (m_cfgCurrent.TryGetValue(strField, out str))
            {
                int nValue;
                if (StrUtil.TryParseInt(str, out nValue))
                {
                    return(nValue);
                }
            }

            return(nDefaultIfNotFound);
        }