学堂 学堂 学堂公众号手机端

C#中怎么使用string.IsNullOrEmpty

lewis 3年前 (2022-04-14) 阅读数 5 #技术

在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"。


版权声明

本文仅代表作者观点,不代表博信信息网立场。

热门