I have string with empty space(\"________\")
string MyNote= Convert.ToString(Session[\"MyNote\"]);
if(MyNote!=null || MyNote != \"\")
{
}
if(MyNote!=null || MyNote.Length > 0) //or you may want to set different value than 0
{
}
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)
{
}
This works for me:
string MyNote = Session["MyNote"] == null ? String.Empty : Session["MyNote"].ToString();