IsNullOrEmpty和IsNullOrWhiteSpace的区别
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的区别的更多相关文章
- IsNullOrEmpty与IsNullOrWhiteSpace性能比较
IsNullOrEmpty与IsNullOrWhiteSpace性能谁比较高呢? 在string都是空字符串的情况下: IsNullOrWhiteSpace要比IsNullOrEmpty快大约 1~5 ...
- IsNullOrEmpty与IsNullOrWhiteSpace区别
IsNullOrEmpty public static bool IsNullOrEmpty(String value) { return (value == null || value.Length ...
- String.IsNullOrEmpty()和String.IsNullOrWhiteSpace()的区别
string.IsNullOrEmpty 这个是判断字符串是否为:null或者string.Empty或者“”,但不包含空格 .如果是如"\t"或者“ ” 这样的字符就返回fa ...
- 【源码分析】你必须知道的string.IsNullOrEmpty && string.IsNullOrWhiteSpace
写在前面 之前自信撸码时踩了一次小坑,代码如下: private static void AppServer_NewMessageReceived(WebSocketSession session, ...
- C# IsNullOrEmpty与IsNullOrWhiteSpace
IsNullOrEmpty:非空非NULL判断 IsNullOrWhiteSpace:非空非NULL非空格判断 后者优于前者 if (!string.IsNullOrWhiteSpace(valueE ...
- Asp.net MVC知识积累
一.知识积累 http://yuangang.cnblogs.com/ 跟蓝狐学mvc教程专题目录:http://www.lanhusoft.com/Article/169.html 依赖注入:htt ...
- LeetCode第五十八题
题目: Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return t ...
- c#常用方法和类
1. 数据类型转换函数 Convert.ToXXX(); XXX.Parse(); XXX.TryParse(); 2. 日期相关的类与函数 获取系统当前日期(含时间):DateTime.Now 获 ...
- csharp: Setting the value of properties reflection
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
随机推荐
- window安装mysql(详细步骤)
前两天电脑炸了,就重新装了系统重新安装了一遍mysql. 首先 你需要有一个安装包哈哈哈,mysql的安装包. 最好不要安装在c盘呦~ 来进入正题吧... ********************** ...
- linux系统网络相关问题
暂时将你的 eth0 这张网络卡的 IP 设定为 192.168.1.100 ,如何进行? ifconfig eth0 192.168.1.100 我要增加一个路由规则,以 eth0 连接 192.1 ...
- 博客主Judge已跳槽搬家emmm
跳槽网站:博客园 顺便带一下:洛谷blog (好久没更了QAQ...) ### 不过csdn上还是会照常更新的,毕竟用着方便
- vue el-tree:默认展开第几级节点
需求描述: Tree 树形结构,默认展开第二级菜单. 查 element 文档: 解决方法: 设置 :default-expanded-keys 的值为 idArr 数组, <el-tree ...
- scrapy 在迭代爬取时被拒 offsite 增加dont_filter=True
- 分布式全文检索引擎之ElasticSearch
一 什么是 ElasticSearch Elasticsearch 是一个分布式可扩展的实时搜索和分析引擎,一个建立在全文搜索引擎 Apache Lucene(TM) 基础上的搜索引擎.当然 Elas ...
- linux_OEL5.4_安装Oracle11g中文教程图解
一.安装ORACLE10g 软件(11.2.0.0) 参考pdf:链接:http://pan.baidu.com/s/1pLHU94J 密码:keo8 (一)安装前的包支持 1. 虚拟机yum 环境搭 ...
- SpringBoot端口和访问路径
更改启动端口:在application.properties配置文件中修改server.port=9090 更改项目访问路径:在application.properties配置文件中修改server. ...
- LeetCode(111):二叉树的最小深度
Easy! 题目描述: 给定一个二叉树,找出其最小深度. 最小深度是从根节点到最近叶子节点的最短路径上的节点数量. 说明: 叶子节点是指没有子节点的节点. 示例: 给定二叉树 [3,9,20,null ...
- hashlib、logging模块
hashlib模块 hashlib提供了常见的摘要算法,如md5和sha1等等. 那么什么是摘要算法呢?摘要算法又称为哈希算法.散列算法.它通过一个函数,把任意长度的数据转换为一个长度固定的数据串(通 ...