C# 奇技淫巧

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/osuckseed/article/details/84879519

1.Enum转数组:

System.Enum.GetValues(typeof(EnumKind));

3.数组合并

using System.Linq;//需要引用

new string[] { "1", "2", "3", "4" }.Concat(new string[] { "a", "b" }).ToArray();

4.定时器的使用

System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();

5.正则表达式

System.Text.RegularExpressions.Regex.IsMatch("nmb", @"^[-]?\d+[.]?\d*$");

6.C# 类型方法扩展:

以字串类型为例:

" 你的偶像是{0}".TTOFormat("张国荣","本山","不二做");

1.1.ToInt();

作用:极大的提升开发效率,减少垃圾代码的出现

public static class TTOFormatHelper
{
    /// <summary>
    /// 字符串格式化新增扩展
    /// </summary>
    /// <param name="_str"> this T para</param>
    /// <param name="values">可变参数数组</param>
    /// <returns></returns>
    public static string TTOFormat(this string _str, params object[] values)
    {
        return string.Format(_str, values);
    }
    public static int ToInt(this float _float)
    {
        return (int)_float;
    }
}

7.持续更新中... ....

猜你喜欢

转载自blog.csdn.net/osuckseed/article/details/84879519