static void Main(string[] args)
{
string str1 = string.Empty;
if (string.IsNullOrEmpty(str1))
{
Console.WriteLine("str1 is empty"); ;
}
string str2 = "";
if (string.IsNullOrEmpty(str2))
{
Console.WriteLine("str2 is empty"); ;
}
string str3 = null;
if (string.IsNullOrEmpty(str3))
{
Console.WriteLine("str3 is empty"); ;
}
Console.ReadKey();
}
运行结果如下:5 S$ N5 e. |, d' M5 V+ h
9 d' d- {2 L1 Z9 |" Z: [0 H
方法三 :但是IsNullOrEmpty在字符串为" ","\n","\t",时候就无能为力了,为了覆盖这些场景,高手们一般判空使用方法IsNullOrWhiteSpace$ i( m5 O! H, i