What is the difference between vbNullString, String.Empty and “”?

后端 未结 3 1657
予麋鹿
予麋鹿 2020-12-07 02:47

All of these

  • txtUsername.Text <> vbNullString
  • txtUsername.Text <> String.Empty
  • txtUsername.Text &
3条回答
  •  渐次进展
    2020-12-07 03:23

    vbNullString is a constant, more likely out of VB6, String.Empty and "" are the same, some say that there is a performance difference, but that is not true, it is your choice what you use.

    To check whether a string is empty you can use If String.IsNullOrEmpty(String). The advantage is that it will also check for null, because string is a class and because of this a reference type.

提交回复
热议问题