在C#中,可以使用以下方法来判断字符串是否为空:
使用 String.IsNullOrEmpty 方法:string str = "test";if (String.IsNullOrEmpty(str)){ Console.WriteLine("String is null or empty.");}else{ Console.WriteLine("String is not null or empty.");}使用 String.IsNullOrWhiteSpace 方法:string str = "test";if (String.IsNullOrWhiteSpace(str)){ Console.WriteLine("String is null, empty, or consists only of white-space characters.");}else{ Console.WriteLine("String is not null, empty, or consists only of white-space characters.");}这两种方法可以帮助您确定字符串是否为空或仅包含空格或制表符等空白字符。


