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. boost.python入门教程 ----python 嵌入c++

    Python语言简介 Python是一种脚本语言.以开放的开发接口和独特的语法著称.尽管Python在国内引起注意只有几年的时间,但实际上Python出现于上世纪90年代(据www.python.or ...

  2. NOI2019 SX 模拟赛 no.5

    Mas 的童年 题目描述:不知道传送门有没有用? 反正就是对于每个前缀序列求一个断点,使得断点左右两个区间的 分别的异或和 的和最大 分析 jzoj 原题? 但是我 TM 代码没存账号也过期了啊! 然 ...

  3. C++代码风格指南总结

    C++代码风格指南 代码风格的重要性 今天我收到thougthwork笔试没过的消息, 心里确实很难受, 然后师兄说我代码写得很糟糕 细想一下, 我写代码确实是随心所欲, 并没有遵循什么规范; 所以现 ...

  4. Qt5.10.1 在windows下vs2017静态编译

    1.在计算机上安装python库和perl库(因为后续的静态编译需要用到这两种语言),可以在命令行敲击“python”和“perl -v”检查是否安装成功. 2.修改msvc-desktop.conf ...

  5. iOS ATS问题(补充中)

    首先,针对2017年一月后,需要提交到apple store的程序,如果使用App Transport Security Settings对程序 ATS情况进行特殊配置,需要对苹果进行说明,指出使用的 ...

  6. Linux IO实时监控iostat命令

    简介 iostat主要用于监控系统设备的IO负载情况,iostat首次运行时显示自系统启动开始的各项统计信息,之后运行iostat将显示自上次运行该命令以后的统计信息.用户可以通过指定统计的次数和时间 ...

  7. Confluence 6 为翻译显示用户界面的键(Key)名称

    这个功能在你使用 Confluence 用户界面为 Confluence 创建翻译的时候会非常有用.当你打开主面板的时候,在你访问的 URL 的最后面添加下面的文字:can add the follo ...

  8. js小方法积累,将一个数组按照n个一份,分成若干数组

    // 把一个数组按照一定长度分割成若干数组 function group(array, subGroupLength) { let index = 0; let newArray = []; whil ...

  9. bat如何实现多台android设备同时安装多个apk

    背景:在做预置资源(安装apk)时,有多台android设备需要做相同的资源(如:10台,安装10个apk).一台一台去预置的话(当然也可以每人一台去预置),耗时较长有重复性. 问题:如何去实现多台同 ...

  10. 【es】创建索引和映射

    参考:http://www.cnblogs.com/sheeva/p/4837881.html 创建索引: curl -XPUT 'http://localhost:9200/some_index' ...