新网创想网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

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

我们通过一个方法判断 (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


网页标题:三种判断字符串为空方法的优先级
URL链接:http://www.wjwzjz.com/article/gcgehi.html
在线咨询
服务热线
服务热线:028-86922220
TOP