成都创新互联网站制作重庆分公司

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

我们通过一个方法判断 (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://cxhlcq.com/article/gcgehi.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部