十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
我们通过一个方法判断 (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