public static void Main(string[] args) { var str = ""; //空字符串的情况 // true Console.WriteLine(string.IsNullOrEmpty(str)); // true Console.WriteLine(string.IsNullOrWhiteSpace(str)); // 空格的情况 str = " "; // false Console.WriteLine(string.IsNullOrEmpty(str)); // true Console.WriteLine(string.IsNullOrWhiteSpace(str)); Console.WriteLine("" .Equals(string.Empty)); }
string.IsNullOrWhiteSpace 还是最合适的。