温馨提示×

C#中怎么使用string.IsNullOrEmpty

c#
小亿
83
2024-04-28 19:07:42
栏目: 编程语言

在C#中,使用string.IsNullOrEmpty方法可以判断一个字符串是否为null或者为空字符串。示例如下:

string myString = "Hello World";

if (string.IsNullOrEmpty(myString))
{
    Console.WriteLine("String is null or empty");
}
else
{
    Console.WriteLine("String is not null or empty");
}

在上面的示例中,如果myString为空或者为null,则会输出"String is null or empty";否则会输出"String is not null or empty"。

0