如何检查字符串数组是否为Null或Empty? [英] how to check string array is Null or Empty?

查看:75
本文介绍了如何检查字符串数组是否为Null或Empty?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查字符串数组是否为Null或为空?

how to check string array is Null or Empty?

推荐答案

if (myArray == null)
   System.Console.WriteLine("array is not initialized");
else if (myArray.Length < 1)
   System.Console.WriteLine("array is empty");



这样的事情.

—SA



Something like that.

—SA


可能会有所帮助,

might helps,

static void Main(string[] args)
{
    string[] myStringArray = null;
    if (IsNullOrEmpty(myStringArray))
        Console.WriteLine("Null or Empty");
}

static bool IsNullOrEmpty(string[] myStringArray)
{
    return myStringArray == null || myStringArray.Length < 1;
}



同样,您可以将IsNullOrEmpty 作为扩展方法:)



also, you can make IsNullOrEmpty as a extension method :)


如果您使用的是数组,则可以检查它的 IsNullOrEmpty [ ^ ]
If you''re using an array, you can check it''s length[^]

On the other hand if you''re using simply a string, you can check IsNullOrEmpty[^]


这篇关于如何检查字符串数组是否为Null或Empty?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆