Code 1namespace my 2{ 3 class Program 4 { 5 static void Main(string[] args) 6 { 7 string a = string.Empty; 8 if (a == "") //执行效率(4) 9 {10 Console.WriteLine(@"a=="" ");11 }12 if (a == string.Empty)//执行效率(3)13 {14 Console.WriteLine("a==string.Empty");15 }16 if (a.Length == 0) //执行效率最高(1)17 {18 Console.WriteLine("a.Length == 0");19 }20 if (string.IsNullOrEmpty(a)) //执行效率(2) 21 {22 Console.WriteLine("a==string.Empty");23 }2425 bool b = IsNullOrEmpty(a);26 Console.WriteLine(b);2728 }2930 /**//// <summary>31 /// 判断字符串是否为空32 /// </summary>33 /// <param name="value">String 类型的值</param>34 /// <returns>返回值 true ,false </returns>35 public static bool IsNullOrEmpty(string value)36 {37 if (value != null)38 {39 return (value.Length == 0);40 }41 return true;42 }4344 }45} 转载于:https://www.cnblogs.com/liuyong/archive/2009/05/25/1489221.html