通过str获得int值 - IntByStr

2017-01-25 17:30:08  访问(1645) 赞(0) 踩(0)


        /// <summary>
        /// 通过str获得int值
        /// </summary>
        /// <param name="str"></param>
        /// <param name="defaultValue"></param>
        /// <returns></returns>
        public int IntByStr(string str, int defaultValue)
        {
            if (str == null)
                return defaultValue;

            if (str.Length == 0)
                return defaultValue;

            int theResult = 0;

            if (int.TryParse(str, out theResult))
                return theResult;

            return defaultValue;
        }


标签:通过str获得int值 - IntByStr 

上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)