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 ...
随机推荐
- js和thinkphp5路由拼接一个实例
$.ajax({ type:"get", dataType:"json", url:"/home/index/ajax_page_data/cate_ ...
- ffmpeg-201701[10,16,21,23,25]-bin.7z
ESC 退出 0 进度条开关 1 屏幕原始大小 2 屏幕1/2大小 3 屏幕1/3大小 4 屏幕1/4大小 5 屏幕横向放大 20 像素 6 屏幕横向缩小 20 像素 S 下一帧 [ -2秒 ] +2 ...
- 我理解的vue生命周期
说些题外话,引出vue的生命周期. 比如人出生到寿终正寝,这是人的一个生命周期.他会经历出生,婴儿时期,童年时期,少年时期,青年,中年,老年,到 end.然后,每个时期都会有一定的历史任务在等着去完成 ...
- websocket:日常总结
1.报错:DefaultHandshakeHandler : Handshake failed due to invalid Upgrade header 参考文章:https://www.cnblo ...
- Find Lines
(Uva 6955可以直接随机,湖大OJ 13348 要优化) 题意:给出 n个点的坐标, 一个 百分数p, 求是否有一条直线上有 n * p /100个点… 随机化算法,但也要优化下……(TLE, ...
- Django ----- 模板2
tags for <ul> {% for user in user_list %} <li>{{ user.name }}</li> {% endfor %} #结 ...
- 安装mysql5.7与创建用户和远程登录授权
环境:ubuntu18.04 参考文章:安装并远程登录授权:https://www.cnblogs.com/chancy/p/9444187.html 用户管理:https://www.cnblogs ...
- 生产环境优雅的重启基于Nginx、Tornado的Web服务进程
Nginx是一个高效的Web服务器及代理服务器,Tornado是一个基于epoll的异步Web开发框架,通常使用Nginx做为Web服务器时,都会以FastCGI模式,而我们从开发.调试.运维的角度考 ...
- mysql 定期删除表中无用数据
MySQL5.1.x版本中引入了一项新特性EVENT,定期执行某些事物,这可以帮助我们实现定期执行某个小功能,不在依赖代码去实现. 我现在有一张表,这张表中的数据有个特点,每天都会有大量数据插入,但是 ...
- 判断iOS版本号
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 4.0) { }