C# IsNullOrEmpty() 方法用于检查指定字符串是空字符串还是空字符串。它返回一个布尔值 true 或 false。
public static bool IsNullOrEmpty(String str)
str:它是一个字符串参数,用于检查字符串。
它返回布尔值。
using System;
public class StringExample
{
public static void Main(string[] args)
{
string s1 = "Hello C#";
string s2 = "";
bool b1 = string.IsNullOrEmpty(s1);
bool b2 = string.IsNullOrEmpty(s2);
Console.WriteLine(b1);
Console.WriteLine(b2);
}
}
输出:
False True