vbNullString、String.Empty 和“"之间有什么区别? [英] What is the difference between vbNullString, String.Empty and ""?
问题描述
所有这些
txtUsername.Text <>vbNullString
txtUsername.Text <>String.Empty
txtUsername.Text <>""
似乎返回相同的结果.那么,vbNullString
、String.Empty
和 ""
有什么区别?
seem to return the same result. So, what's the difference between vbNullString
, String.Empty
and ""
?
推荐答案
vbNullString 是一个常量,更可能是在 VB6 中,String.Empty
和 ""
是同样,有人说有性能差异,但事实并非如此,使用什么是您的选择.
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.
要检查字符串是否为空,您可以使用If String.IsNullOrEmpty(String)
.优点是它还会检查 null,因为 string 是一个类,因此它是一个引用类型.
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.
这篇关于vbNullString、String.Empty 和“"之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!