当前位置: 移动技术网 > IT编程>开发语言>.net > 【转载】C#中string.IsNullOrEmpty和string.IsNullOrWhiteSpace区别

【转载】C#中string.IsNullOrEmpty和string.IsNullOrWhiteSpace区别

2019年06月11日  | 移动技术网IT编程  | 我要评论

木薯洁面仪,强盗与士兵,展示产品

在c#中判断字段是否为空或者null的时候,我们一般会使用到string.isnullorempty和string.isnullorwhitespace方法,这两个方法在大部分情况下判断的结果是一致的,但相比于string.isnullorempty方法,string.isnullorwhitespace方法还会对空白字符进行判断,例如一个字符串全是空格等空白字符的情况,在string.isnullorwhitespace的判断下为false,而string.isnullorwhitespace方法判断则为true。

举例如下:

 string stringd = "   ";//空白字符串

var resultd1 = string.isnullorempty(stringd);
 var resultd2= string.isnullorwhitespace(stringd);

上述语句的结果resultd1=false,resultd2=true。string.isnullorwhitespace方法认定为这种空白字符也是符合规则的,因此返回true。

 

备注:原文转载自博主个人站,原文链接为c#中string.isnullorempty和string.isnullorwhitespace区别_it技术小趣屋

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网