如题

解决方案 »

  1.   

    1.if(a=="")
    2.if(a==String.Empty)
    3.if(a.Length==0)http://www.csharp360.com/bbs/viewthread.php?tid=131&extra=page%3D1
      

  2.   

    string str=string.Empty;
    if(string.IsNullOrEmpty(str))
    {}
      

  3.   

    =="";
    string.IsNullOrEmpty();
    另外:  public static readonly String Empty = ""; MS 源码;
      

  4.   

    用 string.IsNullOrEmpty 函数
      

  5.   

    testdriven.net测试
    http://www.cnblogs.com/homezzm/archive/2009/11/27/1611741.html
      

  6.   


    如果不为null  应该是3快
      

  7.   

    我一直都是用if(string.IsNullOrEmpty(str))
      

  8.   

    if(string.IsNullOrEmpty(str))
    if(a=="")
    if(a==String.Empty)
    if(a.Length==0)
    整数判断等于最快,没有经过实例化等复杂的过程
      

  9.   

    可能为 NULL时 请使用  string.IsNullOrEmpty肯定不为NULL时 a.Length 最快
      

  10.   

    答案好一致啊,我这个跟楼上的都不一样:if(MyHelper.ToString(a)=="")
    ……
    MyHelper.ToString()代码如下:
    public static string ToString(object pObj)
    {
        try
        {
            return Convert.ToString(pObj).Trim();
        }
        catch
        {
            return "";
        }
        finally
        {    }
    }
      

  11.   

    有这么几种方式:someString=="";或someString.Length==0;或System.String.IsNullOrEmpty(someString);或someString==System.Empty;
    用reflector 查看System.String 类型的定义:
    知:(1)System.String.IsNullOrEmpty 定义如下:
    public static bool IsNullOrEmpty(string value)
    {
        if (value != null)
        {
            return (value.Length == 0);
        }
        return true;
    }
    (2)至于System.String 的实例的Length属性,不用管它,Length==0字符串肯定为空;由(1)、(2)知someString.Length==0;和System.String.IsNullOrEmpty(someString)是一样样的;(3)(不知道什么原因,我的reflector无法查看System.String中的重载运算符“==”),Ms给的“==”重载的说明是:public static bool operator ==(string a, string b)
        Member of System.StringSummary:
    Determines whether two specified strings have the same value.Parameters:
    a: The first string to compare, or null.
    b: The second string to compare, or null.Returns:
    true if the value of a is the same as the value of b; otherwise, false.如果用someString==""来用,我觉得可能会经过更多的步骤来判断someString 和空字符串的关系,效率可能会比System.String.IsNullOrEmpty稍低。
    (4)System.String.Empty的定义是:
    public static readonly String Empty = "";
    所以someString==System.Empty 和someString==""应该是一样的。
      

  12.   

    @lz:
    应该使用string.IsNullOrEmpty()方法.
    此方法既判断该字符串是否为Null值又判断是否为""值.
    一举两得!
      

  13.   

    string.IsNullOrEmpty()只能是引用类型可以是null的?
      

  14.   

    string a="";
    1.if(a=="")
    2.if(a==String.Empty)
    3.if(a.Length==0)
      

  15.   

    if(a!=null&&a.Length!=0)
    用不等于~~效率搞点!呵呵
      

  16.   

    if(string.IsNullOrEmpty(str))
    我觉得还是这条高!
      

  17.   

    good goog study, day day up!
      

  18.   

    good goog study, day day up!
      

  19.   

    CPU执行最快的方法:
    if(a==""||a==null)