三种判断字符串为空方法的优先级

我们通过一个方法判断 (1.str == ""  2.str == String.Empty  3.str.Length == 0)

成都地区优秀IDC服务器托管提供商(成都创新互联).为客户提供专业的电信内江机房,四川各地服务器托管,电信内江机房、多线服务器托管.托管咨询专线:18980820575

static void Main()
        {
            string str = "csdn";
            System.Diagnostics.Stopwatch st = new System.Diagnostics.Stopwatch();
            st.Start();
            for (int i = 0; i < 100000000; i++)
            {
                if (str == "")
                { }
            }
            st.Stop();
            Console.WriteLine("str == '' : " + st.ElapsedMilliseconds);
            st = new System.Diagnostics.Stopwatch();
            st.Start();
            for (int i = 0; i < 100000000; i++)
            {
                if (str == String.Empty)
                { }
            }
            st.Stop();
            Console.WriteLine("str == String.Empty : " + st.ElapsedMilliseconds);
            st = new System.Diagnostics.Stopwatch();
            st.Start();
            for (int i = 0; i < 100000000; i++)
            {
                if (str.Length == 0)
                { }
            }
            st.Stop();
            Console.WriteLine("str.Length == 0 : " + st.ElapsedMilliseconds);
            Console.ReadKey();
        }


F5 用行
str == '': 1951  (微妙为单位)
str =='': 1867
str =='': 522


当前标题:三种判断字符串为空方法的优先级
本文网址:http://lszwz.com/article/gcgehi.html

其他资讯

售后响应及时

7×24小时客服热线

数据备份

更安全、更高效、更稳定

价格公道精准

项目经理精准报价不弄虚作假

合作无风险

重合同讲信誉,无效全额退款