str==""
str.Length==0
str==String.Empty
这是三种用来判断字符串是否为空的方法,那么这三种方法哪一种执行起来更快呢?
为了得出结果,我在vs.net 2005中写了下面这一小段程序来进行判断:
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
namespace ConsoleApplication1
{
class Test
{
public static void Main()
{
string str = "ljdfskldfsklj";
//System.Diagnostics.Stopwatch提供了一组方法和属性,可以准确地测量运行时间
Stopwatch sw;
sw=Stopwatch.StartNew();
if (str == "") ;
Console.WriteLine("str==/