vbNullString、String.Empty 和“"之间有什么区别? [英] What is the difference between vbNullString, String.Empty and ""?

查看:62
本文介绍了vbNullString、String.Empty 和“"之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有这些

  • txtUsername.Text <>vbNullString
  • txtUsername.Text <>String.Empty
  • txtUsername.Text <>""

似乎返回相同的结果.那么,vbNullStringString.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆