如何检查字符串数组是否为Null或Empty? [英] how to check string array is Null or Empty?
本文介绍了如何检查字符串数组是否为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");
这样的事情.
Something like that.
可能会有所帮助,
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 :)
如果您使用的是数组,则可以检查它的 ^ ]
另一方面,如果仅使用string
,则可以检查 IsNullOrEmpty [ ^ ]
If you''re using an array, you can check it''s length[^]
On the other hand if you''re using simply astring
, you can check IsNullOrEmpty[^]
这篇关于如何检查字符串数组是否为Null或Empty?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文