IsNullOrEmpty

// string
/// <summary>Indicates whether the specified string is null or an <see cref="F:System.String.Empty" /> string.</summary>
/// <param name="value">The string to test. </param>
/// <returns>true if the <paramref name="value" /> parameter is null or an empty string (""); otherwise, false.</returns>
[__DynamicallyInvokable]
public static bool IsNullOrEmpty(string value)
{
return value == null || value.Length == ;
}

IsNullOrWhiteSpace

// string
/// <summary>Indicates whether a specified string is null, empty, or consists only of white-space characters.</summary>
/// <param name="value">The string to test.</param>
/// <returns>true if the <paramref name="value" /> parameter is null or <see cref="F:System.String.Empty" />, or if <paramref name="value" /> consists exclusively of white-space characters. </returns>
[__DynamicallyInvokable]
public static bool IsNullOrWhiteSpace(string value)
{
if (value == null)
{
return true;
}
for (int i = ; i < value.Length; i++)
{
if (!char.IsWhiteSpace(value[i]))
{
return false;
}
}
return true;
}

后者比前者更严谨,指示指定的字符串是 null、空还是仅由空白字符组成。

IsNullOrEmpty和IsNullOrWhiteSpace的区别的更多相关文章

  1. IsNullOrEmpty与IsNullOrWhiteSpace性能比较

    IsNullOrEmpty与IsNullOrWhiteSpace性能谁比较高呢? 在string都是空字符串的情况下: IsNullOrWhiteSpace要比IsNullOrEmpty快大约 1~5 ...

  2. IsNullOrEmpty与IsNullOrWhiteSpace区别

    IsNullOrEmpty public static bool IsNullOrEmpty(String value) { return (value == null || value.Length ...

  3. String.IsNullOrEmpty()和String.IsNullOrWhiteSpace()的区别

    string.IsNullOrEmpty 这个是判断字符串是否为:null或者string.Empty或者“”,但不包含空格 .如果是如"\t"或者“   ” 这样的字符就返回fa ...

  4. 【源码分析】你必须知道的string.IsNullOrEmpty && string.IsNullOrWhiteSpace

    写在前面 之前自信撸码时踩了一次小坑,代码如下: private static void AppServer_NewMessageReceived(WebSocketSession session, ...

  5. C# IsNullOrEmpty与IsNullOrWhiteSpace

    IsNullOrEmpty:非空非NULL判断 IsNullOrWhiteSpace:非空非NULL非空格判断 后者优于前者 if (!string.IsNullOrWhiteSpace(valueE ...

  6. Asp.net MVC知识积累

    一.知识积累 http://yuangang.cnblogs.com/ 跟蓝狐学mvc教程专题目录:http://www.lanhusoft.com/Article/169.html 依赖注入:htt ...

  7. LeetCode第五十八题

    题目: Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return t ...

  8. c#常用方法和类

    1.  数据类型转换函数 Convert.ToXXX(); XXX.Parse(); XXX.TryParse(); 2. 日期相关的类与函数 获取系统当前日期(含时间):DateTime.Now 获 ...

  9. csharp: Setting the value of properties reflection

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

随机推荐

  1. centos配置小程序https和wss协议

    用nginx做代理,conf.d下ssl.conf配置成https,wss在nginx.conf里http某块中配置 例代码如下: ssl.conf-->https server { liste ...

  2. 【转】Linux下gcc生成和使用静态库和动态库详解

    一.基本概念 1.1 什么是库 在Windows平台和Linux平台下都大量存在着库. 本质上来说,库是一种可执行代码的二进制形式,可以被操作系统载入内存执行. 由于windows和linux的平台不 ...

  3. [JLOI2011]飞行路线 不同的算法,不同的悲伤

    题目 :BZOJ2763 洛谷P4568 [JLOI2011]飞行路线 一道最短路的题目,想想写个题解也不错(好久没写题解了_(:з」∠)_) 然后这道题中心思路是dijikstra处理最短路,所以没 ...

  4. SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data错误的解决

    记录个报错: 问题描述: 经过服务器生成图片返到前台时,在火狐浏览器中下载图片或打开图片时报错:SyntaxError: JSON.parse: unexpected character at lin ...

  5. AngularJs 刷新页面

    第一种: AngularJs 刷新页面可采用下面的方式:首先先在控制器中注册$window,然后定义函数$scope.reloadRoute,在需要刷新页面的地方调用函数$scope.reloadRo ...

  6. 【原创】大数据基础之Logstash(3)应用之http(in和out)

    一个logstash很容易通过http打断成两个logstash实现跨服务器或者跨平台间数据同步,比如原来的流程是 logstash: nginx log -> kafka 打断成两个是 log ...

  7. Druid监控页面配置与使用

    一.Maven中添加Durid连接池依赖 <!-- druid连接池 --> <dependency> <groupId>com.alibaba</group ...

  8. [MySQL]多表关联查询技巧

    示例表A: author_id author_name 1 Kimmy 2 Abel 3 Bill 4 Berton 示例表B: book_id author_id start_date end_da ...

  9. IP保留地址

    保留地址的网络只能在内部进行通信,而不能与其他网络互连.因为本网络中的保留地址同样也可能被其它网络使用,如果进行网络互连,那么寻找路由时就会因为地址的不唯一而出现问题. 但是这些使用保留地址的网络可以 ...

  10. mac系统 安装 JDK 并配置环境

    第一步 : 下载 mac 版的 JDK 下载地址: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-213 ...