Check string is null or empty in linq

后端 未结 3 927
一生所求
一生所求 2021-01-21 23:24

I have string with empty space(\"________\")

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

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


}
         


        
3条回答
  •  -上瘾入骨i
    2021-01-21 23:59

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

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

    Alternatively, using your idea:

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

    or

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

提交回复
热议问题