Nothing = String.Empty (Why are these equal?)

前端 未结 4 935
春和景丽
春和景丽 2020-12-01 15:58

Why does the first if statement evaluate to true? I know if I use \"is\" instead of \"=\" then it won\'t evaluate to true. If I replace String.Empty with \"Foo\" it doesn\

4条回答
  •  自闭症患者
    2020-12-01 16:40

    It's a special case of VB's = and <> operators.

    The Language Specification states in Section 11.14:

    When doing a string comparison, a null reference is equivalent to the string literal "".


    If you are interested in further details, I have written an in-depth comparison of vbNullString, String.Empty, "" and Nothing in VB.NET here:

    • https://stackoverflow.com/a/34069187/87698

提交回复
热议问题