IsNullOrEmpty(string)是String类的一个有参的方法,方法需要类的调用,所以String.IsNullOrEmpty(string)
IsNullOrEmpty是判断字符串的Null值和""值。如果字符串为空或为""都返回true。
string.IsNullOrEmpty(null)---返回true
string.IsNullOrEmpty("")---返回true
if (String.IsNullOrEmpty(str))
返回false,才表示str即不为空也不为""。
举例:
anywhere = "where 1=1 and f.Facility is not null and f.Company is not null ";
if (!string.IsNullOrEmpty(Facility))
{
anywhere += " and f.Facility like N'%" + Facility + "%'";
}
if (!string.IsNullOrEmpty(Company))
{
anywhere += " and f.Company like N'%" + Company + "%'";
}