测试三种常用的字符串判空串方法所耗的时间,出什么问题了?

liucom liucom 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
using System;
using System.Threading;
public class strLengthTime
{
public static void Main()
{
string strTest="";
string strSub;
for(int i =0 ;i< 1000;i++)
{
strSub=i.ToString();
strTest = strTest + strSub;
}
//System.Console.WriteLine(strTest);
DateTime startTime;
DateTime endTime;
TimeSpan timeCost;
startTime =DateTime.Now;
if(strTest.Length==0)
{
System.Console.WriteLine("Not A Null String!");
}
else
{
endTime=DateTime.Now;
timeCost=endTime - startTime;
System.Console.WriteLine("strTest.Length Method Costs:"+timeCost.ToString());
}
Thread.Sleep(1000);
startTime = DateTime.Now;
if(strTest==String.Empty)
{
System.Console.WriteLine("Not A Null String!");
}
else
{
endTime=DateTime.Now;
timeCost= endTime - startTime;
System.Console.WriteLine("String.Empty Method Costs:"+timeCost.ToString());
}
Thread.Sleep(1000);
startTime = DateTime.Now;
if(strTest=="")
{
System.Console.WriteLine("Not A Null String!");
}
else
{
endTime=DateTime.Now;
timeCost= endTime - startTime;
System.Console.WriteLine("The Third Method Costs:"+timeCost.ToString());
}
}
}

输出的结果都是00:00:00,出什么问题了?
...全文

相关推荐

评论 5
收藏 已收藏
分享
返回顶部
liucom
智能路由器 684 成员 913 内容