在C#中,IsNullOrEmpty是一个静态方法,用于判断一个字符串是否为null或者空字符串。使用时,直接通过字符串类型调用该方法即可。以下是使用示例:
string str1 = null;string str2 = "";string str3 = "Hello World";if (string.IsNullOrEmpty(str1)){ Console.WriteLine("str1 is null or empty");}else{ Console.WriteLine("str1 is not null or empty");}if (string.IsNullOrEmpty(str2)){ Console.WriteLine("str2 is null or empty");}else{ Console.WriteLine("str2 is not null or empty");}if (string.IsNullOrEmpty(str3)){ Console.WriteLine("str3 is null or empty");}else{ Console.WriteLine("str3 is not null or empty");}输出结果为:
str1 is null or emptystr2 is null or emptystr3 is not null or empty以上示例中,IsNullOrEmpty方法分别判断了str1、str2和str3是否为null或空字符串,并根据判断结果输出相应的信息。

