编写健壮代码的最佳方式是什么,以便可以检查变量是否为空。
例如:
string a;
if((a != null) && (a.Length() > 0))
{
    //do some thing with a
}发布于 2010-05-25 16:59:22
对于字符串,有
if (String.IsNullOrEmpty(a))发布于 2010-05-25 17:03:26
您可以定义一个扩展方法,以允许您在许多事情上执行此操作:
static public bool IsNullOrEmpty<T>(this IEnumerable <T>input)
{
    return input == null || input.Count() == 0;
}如前所述,它已经作为字符串的System.String类中的静态方法存在。
发布于 2010-05-25 17:04:59
如果你使用的是.NET 4.0,你可能想看看String.IsNullOrWhiteSpace。
https://stackoverflow.com/questions/2903241
复制相似问题