TryParseInt() 공개 정적인 메소드

public static TryParseInt ( string str, int &n ) : bool
str string
n int
리턴 bool
예제 #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);
        }
예제 #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);
        }