检查字符串为空或空LINQ [英] Check string is null or empty in linq

查看:1062
本文介绍了检查字符串为空或空LINQ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有字符串空( ________

string MyNote= Convert.ToString(Session["MyNote"]);

if(MyNote!=null || MyNote != "")
{


}

MyNote!=不工作,如果字符串有更多的空间,让

MyNote != "" does not work if string has more space so

如何我检查我的字符串是?还是空在C#中使用LINQ

How can I check my string is "" or null by using linq in C#?

推荐答案

String.IsNullOrWhiteSpace 是方法你重新寻找。

String.IsNullOrWhiteSpace is the method you're looking for.

指示指定字符串是否为空,空,或者仅包含空格字符。

Indicates whether a specified string is null, empty, or consists only of white-space characters.

另外,使用你的想法:

if(MyNote!=null && MyNote.Trim() != "")
{

}

if(MyNote!=null && MyNote.Trim().Length == 0)
{

}

这篇关于检查字符串为空或空LINQ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆