String.IsNullOrEmpty()和String.IsNullOrWhiteSpace()

简介: 由于总用 String.IsNullOrEmpty( s ) ,就上网收了一下相关的资料,其实这种用法和s == null || s.Length == 0这种判断方法并无太大区别。

由于总用 String.IsNullOrEmpty( s ) ,就上网收了一下相关的资料,其实这种用法和s == null || s.Length == 0这种判断方法并无太大区别。只是在速度上可能后者比前者快那么一点点(百万毫秒级别上的),但是瑕不掩瑜,前者便于阅读代码。在对效率要求不高的时候,还是使用前者吧。.Net4.0又出现了String.IsNullOrWhiteSpace()这个方法,区别如下图。据说效率很高。具体没有验证过。

 

image

作者:塞北隐士
出处:http://www.cnblogs.com/xiangyun/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利

image


 

转自博客:

http://www.cnblogs.com/xiangyun/archive/2010/09/07/1820944.html

相关文章
|
1月前
|
C#
C#中IsNullOrEmpty和IsNullOrWhiteSpace的区别?
C#中IsNullOrEmpty和IsNullOrWhiteSpace的区别?
For input string: "null"
java.lang.NumberFormatException: For input string: "null"   在开发中你是否遇到过这样的问题,不管请求到的值是什么都能进入不为null或”“的判断中,如下例:      Stringtemp=req.
3817 0
|
5月前
|
编译器
error TS2322 Type ‘string null‘ is not assignable to type ‘string undefined‘.
error TS2322 Type ‘string null‘ is not assignable to type ‘string undefined‘.
91 1
|
9月前
|
C# 开发者
C#中IsNullOrEmpty和IsNullOrWhiteSpace的使用方法有什么区别?
C#中IsNullOrEmpty和IsNullOrWhiteSpace的使用方法有什么区别?
String.search()
String.search()
70 0
|
JavaScript
String.match()
String.match()
74 0
|
索引
string.find
string.find
106 0
string.match
string.match
85 0
string.gsub
string.gsub
190 0
|
存储 Java 数据安全/隐私保护