liaoxujun@qq.com
2024-02-23 6e831c9dd9a46a1dbd727f5f06068c10aef99b46
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace utils
{
    /// <summary>
    /// string 扩展函数
    /// </summary>
    public static class StringExtensions
    {
        /// <summary>
        /// str转int扩展函数
        /// </summary>     
        /// <param name="defaultValue"> 转换失败返回默认值</param>
        /// <returns></returns>
        public static int ToInt32(this string value, int defaultValue = 0)
        {
            int result;
            if (int.TryParse(value, out result))
            {
                return result;
            }
            else
            {
                return defaultValue;
            }
        }
    }
}