概要
经常会用到,判断字符是非为“”和null的情况。判断到不难,但是每次都很麻烦。看看有没有封装的更简单的函数,因为这个场景会经常用,一看真有。
代码
namespace 判断字符串是否为空2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("判断字符串是否为空");
string atr = null;
if (string.IsNullOrEmpty(atr)) {
Console.WriteLine("字符串为null");
}
string str2 = "";
if (string.IsNullOrEmpty(str2)) {
Console.WriteLine("字符串为\"\"");
}
Console.ReadKey();
}
}
}
运行结果